Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need Help In Creating A Decimal to Hexadecimal Program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kenster102.5




PostPosted: 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



HextoDecimal.t
 Description:
Decimal to Hex generator

Download
 Filename:  HextoDecimal.t
 Filesize:  678 Bytes
 Downloaded:  63 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
LaZ3R




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: