RyanHan
Junior Member level 3
Dear all,
I am trying to find a better way to convert a string of 4 Hex character to integer so that I can do the compare and do necessary action.
I am using a wireless communication to get ADC value from sensors and the return was string character of the value in Hex.
e.g. from 0000 to 2EEE.
I saw the atoi function in Keil C but it can only convert 0-9 and not A to F. Is there any function that can convert this 2 bytes data into integer?
Currently my method of conversion was quite lengthy. I will use a lookup table and convert all the string Hex into binary
e.g. 'F' (0x46) --> 0x0F, merge the individual 4 bit into a byte, then merge the 2 byte into an integer. Then only I can process the integer.
Anyone had a better idea? Pls share. Thanks a lot
I am trying to find a better way to convert a string of 4 Hex character to integer so that I can do the compare and do necessary action.
I am using a wireless communication to get ADC value from sensors and the return was string character of the value in Hex.
e.g. from 0000 to 2EEE.
I saw the atoi function in Keil C but it can only convert 0-9 and not A to F. Is there any function that can convert this 2 bytes data into integer?
Currently my method of conversion was quite lengthy. I will use a lookup table and convert all the string Hex into binary
e.g. 'F' (0x46) --> 0x0F, merge the individual 4 bit into a byte, then merge the 2 byte into an integer. Then only I can process the integer.
Anyone had a better idea? Pls share. Thanks a lot