Converting denary to ascii

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Brill

Converting denary to ascii

Post by Brill »

How do i convert a denary number to ascii. I worked out converting hex, that was easy, but denary is proving hard.
Heh, it's probably staring me right in the face.
Any help would be appreciated :)

Thanks.
Brill.
Keith

RE:Converting denary to ascii

Post by Keith »

Since you didn't ask to convert to an ASCII string, I assume you just want to initially treat your floating point number as an integer.  The answer is, each FP number (denary number), has a particular position to where the left is whole numbers and to the right are fractionals.  Therefore, it's more or less just a matter of shifting X number of spaces to the right (this will truncate, of course).  Otherwise, you would need to add the right values together, find out if it is .51 or better prior to incrementing the whole number by 1, then converting it to ASCII.  I hope this gives you some insight.  

Cheers,

Keith
Brill

RE:Converting denary to ascii

Post by Brill »

Ok, it helps kind of.
I have a function called prinh. I migh change it to run inside my print function at a later time. But, this is how it works.
I call printh with edx as the hex characters i want to print.
printh takes the top nibble,  copies and zeros everything else in the copy.
it then cmp's it to find out if it's a number or a letter in hex. And then adds a denary value to it depending on that compare. Moves the new ascii character into a byte of storage, and then calls print with esi pointing to that storage, then loops over untill all nibbles inside edx are printed.

This is the kind of funtion im looking for. Now i can convert numbers up to the value of 9 because that's easy, it's 9, add x amount to it (i dont know what now it's ascii so we call print. But, i can't figure out how to print anything larger than 9. Say 10 for example. because that turns into 2 ascii char's and if i wanted to create it based on a similar approach to my printh function above i would have to loop twice round to make the conversion, but i can't figure out how i would do it at that higher level. If you understand me.

Cheers, Brill.
Post Reply