String representation of numbers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

String representation of numbers

JG1993
Hi,

I got stuck at the string representation of numbers, section 12.1.2. In the string2int method, what are we actually doing? Are we converting from decimal to binary? Or are we converting from characters to ASCII?  English is not my first language, so it is possible I translated something wrong as this is completely lost on me.

Reply | Threaded
Open this post in threaded view
|

Re: String representation of numbers

cadet1620
Administrator
int2String converts a 16-bit 2's-compliment integer to a String containing the ASCII characters for the base 10 representation of the integer.

int2String(-123) should return a String with the characters '-', '1', '2', '3'.

string2Int does the reverse, converting a String containing the base 10 representation of a number to a 16-bit 2's-compliment integer.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: String representation of numbers

JG1993
Thank you! I think I might understand it now.

So if I had int2string(99), I would convert the 9s into base 10 and then append it, where I would have to use the ASCII code for those numbers.

And in case of the string2Int method, I would get a string, then find the ASCII code for each character, got the number in base 10 from it, convert it to binary and return.

Would that be correct?
Reply | Threaded
Open this post in threaded view
|

Re: String representation of numbers

cadet1620
Administrator
Yes,

That is correct.