PDA

View Full Version : Converting ASCII HEX digits to decimal...



johnmaetta
- 13th February 2012, 20:22
My project recieves an ASCII text string such as "3FE35853" and stores them in an array. I need to convert each ASCII byte in the array to its decimal equivalent.

example:
"3" = 3
"F" = 15
"E" = 14

Is there an easy way to do this without using a lookup table?


Thanks,

John

Ioannis
- 13th February 2012, 21:53
Are you sure it is not pairs like '3F', 'E3','58','53'?

If it is the you can use HEX modifier.

e.g. HSERIN [hex2 byte1, hex2 byte2, hex2 byte3, hex2 byte4]

Ioannis

Gusse
- 13th February 2012, 22:39
Or this might be one option and you can make it easily scalable beyond 8 bit input string...

Hex_input var byte
ASCII_Array VAR BYTE [8]
i var byte

for i = 0 to 7
DEBUGIN [HEX1 Hex_input]
ASCII_Dec_Array[i] = Hex_input
next i

johnmaetta
- 14th February 2012, 15:29
Thank you. That will work.

John