I have an unsigned char array where I would like to parse its first four elements as HEX values.
I receive and unsiged char array a[],whose content is this
for (int i = 0; i < l; i++) { SerialUSB.print(" Index : "); SerialUSB.print(i); SerialUSB.print(" ,Unsigned Char "); SerialUSB.print( a[i]); SerialUSB.print(", CHAR "); SerialUSB.print( (char) a[i]); SerialUSB.println(); } Index:0 ,Unsigned Char 98, CHAR b Index:1 ,Unsigned Char 49, CHAR 1 Index:2 ,Unsigned Char 53, CHAR 5 Index:3 ,Unsigned Char 57, CHAR 9 Index:4 ,Unsigned Char 55, CHAR 7 Index:5 ,Unsigned Char 56, CHAR 8 Index:6 ,Unsigned Char 85, CHAR U Index:7 ,Unsigned Char 55, CHAR 7 Index:8 ,Unsigned Char 56, CHAR 8 Index:9 ,Unsigned Char 85, CHAR U Index:10 ,Unsigned Char 55, CHAR 7 Index:11 ,Unsigned Char 56, CHAR 8 Index:12 ,Unsigned Char 85, CHAR U How can I get the HEX value of the first four elements of array a[]
inHex[0] = 0xB; // 0xB = 11 inHex[1] = 0x15; // which should come from having concatenated the values `a[1]= '1'` algong with `a[2]='2'` inHex[3] = 0x9; // which should be the char value of a[3] in HEX Thanks in advance.
aetc?!a[2]='2'? Do you wan to get 4 different integers for each of0xb,0x1,0x5,0x9?inHex[0] = 0x11; // which should come from having converted toHEX( (char) a[0] )- this is complete mess, nothing makes sense. it's not to hex, but from hex, result of toHex is a string, if you want to get integers then it's from hex.bor 'B' if treated as a hex digit means11, or0xbif written to hex.0x11!? Do you understand yourself? Why is that second 0x15 is formed by strcat(a[1],a[2])?b I would interpreate it as the HEXadecimal representation B- what is the difference?0xb== 0xB