 This topic has 2 replies, 3 voices, and was last updated 7 years, 5 months ago by .
Viewing 3 posts  1 through 3 (of 3 total)
Viewing 3 posts  1 through 3 (of 3 total)
 You must be logged in to reply to this topic.

Microcontroller › 8051 › Give me Hex to decimal & decimal to ascii conversion
Hello friends,
I m very much trouble to find out the conversion of HEX to DECIMAL and DECIMAL to ASCII, in asm programing.
will u please help me to make both conversion???
i must need both conversion separatly.
please help me.. thanx in advace..
Hi Kunal
Firstly, I would like to correct you on the DECIMAL to ASCII conversion part, both of them are same stuff; ASCII is represented in decimals only. Now for the HEX to DECIMAL part, multiply each hexadecimal digit with (2^(4*pos)) where "pos" is the position of that particulat digit counting from right side with rightmost position marked zero '0'. For example:
if 0xAB45 is to be converted into decimal then its decimal equivalent would be calculated somewhat like this
5*(2^(4*0)) + 4*(2^(4*1)) + 11*(2^(4*2)) + 10*(2^(4*3))= 43845
Hope this helps
if u want in asm programming then its very easy
1) saparate upper and lower nibble of HEX data using masking
2) shift upper nibble to right by 4 position
3) multiply uppper nibble data by 16
4) add the result with lower nibble
here is HEX to decimal conversion is complete
5) now again saparate upper and lower nibbles
6) add 30h (or 48d) in both nibbles to get ASCII values