You can decrypt the right digit as follows:
const unsigned int bcdDigit = bcdNumber & 0xf;
then you can shift the number to the right so that the next digit becomes the rightmost:
bcdNumber >>= 4;
This will give you the numbers in the wrong order though (from right to left). If you know how many digits you have, you can, of course, directly extract the correct bits.
Use for example. (bcdNumber >> (4 * digitIndex)) & 0xf; to extract the digit digitIndex : th, where the digit 0 is the digitIndex .
source share