number to text
number to text
(OP)
how do I convert a number to text?
i.e the number 1000 to "1000"
i.e the number 1000 to "1000"
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS Contact USThanks. We have received your request and will respond promptly. Come Join Us!Are you a
Computer / IT professional? Join TekTips Forums!
*TekTips's functionality depends on members receiving email. By joining you are opting in to receive email. Posting Guidelines 

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love TekTips Forums:
Register now while it's still free!
Already a member? Close this window and log in.
RE: number to text
RE: number to text
(2) Unfortunately this will give you the digits in the reverse of the correct order... check it on paper. You will need to reverse the digits. Have a little think about how to do that and reply again if you get stuck.
(3) Now you need to output each digit as text. That means converting each digit to ascii. Write out a little conversion table on paper of 0 to "0" ascii etc... up to 9. It will become obvious how to make the conversion.
(4) You will have to have a think about your operating system for how to output an ascii. If in dos, have a look at the functions of int 021h.
RE: number to text
divide the number by 10
add 48 to the remainder to convert to ascii
store result in an array
repeat above with quotient, storing result in array in descending elements
btw, I'm using masm32.
RE: number to text
Obviously when you've divided your number down to zero then you can stop, and that way you won't even get leading zeros.
One day someone will explain to me how to print out a decimal from a binary floating point....
RE: number to text
The most significant bit (bit31 for single precision or bit 63 for double precision) is the sign. 0 is +, 1 is .
For single precision (32 bit) the next 8 bits (bit30  bit23) are the exponent. For double precision (64 bit) the next eleven bits (bit 62  bit 52) are the exponent.
In single precision, a bias of 127 is added to the exponent. In double, a bias of 1023 is added.
The mantissa or significand are the remaining bits. Since the first digit of the number is always one, it is not explicity stored in the floating point format.
Subtract the bias from the exponent and convert into decimal.
If the exponent is positive, the integer portion of the number is 1 (always there though not specified) followed by the bits from the most significant bit of the mantissa ((bit 22 for single precision, bit 51 for double) to msbexponent+1.
i.e. if the floating point number is stored as
01000011100110011001100110011001 (32 bit)
the sign is +,
the biased exponent is 10000111,
and the mantissa is 00110011001100110011001
The exponent becomes 10000111  01111111 = 1000 base2 or 8 base10.
The integer part of the mantissa is 100110011 (notice the 1 in the msb position followed by the first 8 digits of the mantissa).
Convert this to decimal to get 307.
For the fractional part you take the remaining bits of the mantissa and multiply that value by 2^exponent.
001100110011001 * 2^8 = 00110011001101 * 100000000 = 110011001100100000000 base2 or 1677568 base10.
The final result then is 307.1677568
RE: number to text
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.
RE: number to text
Lionel