Computer Science Canada

Need Help In Creating A Decimal to Hexadecimal Program

Author:  Kenster102.5 [ Mon Apr 07, 2008 6:28 pm ]
Post subject:  Need Help In Creating A Decimal to Hexadecimal Program

I am creating a program that takes Decimal numbers and results in a Hexadecimal number
I have figured it out so far, but I keep on getting a "String generated by string catenation too long"

function dectohex (input : int) : string

var hex := input
var hexa := ""
var hexadigit := 0

loop

hexadigit := hex mod 16

if hexadigit > 9 then

if hexadigit = 10 then

hexa := "A" + hexa -------------------> This is where the error message occurs.

elsif hexadigit = 11 then
hexa := "B" + hexa

elsif hexadigit = 12 then
hexa := "C" + hexa

elsif hexadigit = 13 then
hexa := "D" + hexa

elsif hexadigit = 14 then
hexa := "E" + hexa

elsif hexadigit = 15 then
hexa := "F" + hexa


end if

else hexa := intstr(hexadigit)
hex := hex div 16
exit when hex = 0

end if

end loop


end dectohex

put dectohex (10)

----------------------------------------------------------
Also what else do I need to get a result of A, B, C, D, E, or F, and where do I place the result statement.
Thank you
Ken

Author:  LaZ3R [ Mon Apr 07, 2008 7:48 pm ]
Post subject:  RE:Need Help In Creating A Decimal to Hexadecimal Program

First of all, use the syntax code if you ever want to post code again.

Secondly... just LOOK at your code...

The value of HEX isn't changing after you leave the if statement within the loop, so you're constantly getting a value of 10 for hexadigit and you will constantly be entering the first part of the if statement which is adding an "A" to the hexa string.

Strings can only store maximum of 255 characters and that's why yuo are a getting that error when you run it.

Fix it.


: