We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I want a code for converting a 32bit hexadecimal number to its decimal ascii equivalent. I mean if number is 0x1234, then its decimal will be 4660 and its ascii equivalent will be 34 36 36 30.
I am not able to do this conversion. Pl advice.
Regards, Unnati.
http://www.keil.com/support/man/docs/c51/c51_lib_stream.htm
You say hex to ASCII, but do you really have a string 0x1234?
If all you have is a number, then there is no "hex" involved.
Hexadecimal is a way of presenting a number. But internally to the processor, it's just a number. You may decide if you want to present the number as binary, hexadecimal, octal, decimal, or using any other numeric base.
Think about how you would do it manually - with pencil & paper...
There is a hex number which needs to be sent via serial communication to other device which accepts the number in ascii format. Eg. I have this number 0x1234 and I need to send 34 39 39 30 (0x1234 = 4990 in dec). Internally in keil, all the numbers are treated in hex and not decimal. Then how do I do this conversion?
"There is a hex number"
No, there isn't - at this point, there is just a number. Did you not read Per's post?
"which needs to be sent via serial communication to other device which accepts the number in ascii format"
It is only when it has to be represented in some output format like this that you have to decide what notation to use; eg, Hex.
"Internally in keil, all the numbers are treated in hex and not decimal"
No!
Again, internally they are just numbers - hex and decimal are irrelevant!
"Then how do I do this conversion?"
You can use one of the library functions that has already been pointed out to you.
But you really should understand how to do this by hand - it is school maths!
use hex to ascii converter.