hello i have an array of 3 bytes unsgined char and i want to convert the 3 byte (hex) array to 1 byte (hex value). values in the array are between 0 - 9 only.
unsigned char buf[3], output; buf[0] = 0x01; buf[0] = 0x02; buf[0] = 0x03;
i want an output as follow: 123 in HEX => output = 0x7B
i tried 'sscanf' and i haven't succeeded. please help.
sounds pretty simple to me: all you have to do is multiply your most significant byte by 100 add to it the next byte multiplied by 10, and then add the least significant byte. then all you have to do printf or sprintf your data.
thanks very much, easy.
printf("\n%bx", buf[0]*100 + buf[1]*10 + buf[2]);
Of course, the whole thing will produce unexpected results if the resulting number would be greater than 255.