Home > Blockchain >  How to convert Int Hex Array To Char
How to convert Int Hex Array To Char

Time:09-16

I have a this type of array:

uint8_t mArray[3] = {0x20,0x40,0x48};

But I need to convert this data like this as an integer 20,40,48. It's weird but the sensor sending this data like this. If the sensor wants to send decimal 20, it sends 0x20.

How can I convert "0x20" value to as a integer "20" in C?

CodePudding user response:

You receive data in BCD format

int fromBCD(unsigned char b)
{
    int result = (b & 0x0f)   10 * (b >> 4);
    return result;
}
  •  Tags:  
  • c
  • Related