Decoding 32bit BCD

Hello All,
Please help me with decoding 32bit BCD,
In my particular case each 4 bits will always have a hex value of 0-9 so retaining the hex values would be sufficient - if this could be a shortcut.
for e.g.
the hex frame would be:13 55 24 01
The base 64 Lorawan payload would be: ASRVEw
I need to decode to: 01 24 55 13 and not decimal 19158291
Appreciate your inputs and time

Update:
I managed to decode each nibble of 4 bits,

function decodeID(bytes) {
return [(bytes[3] >> 4), (bytes[3] & 0x0F), (bytes[2] >> 4), (bytes[2] & 0x0F), (bytes[1] >> 4), (bytes[1] & 0x0F), (bytes[0] >> 4), (bytes[0] & 0x0F)];
}

This returns an array of the results - I need the result in one staring
Please help explain how to go about this ? (Iā€™m guessing it should be simple)
just removing the [] did not work

Thanks again

2 Likes

Updating for reference,
Just simple math :slight_smile:

function decodeID(bytes) {
return ((bytes[3] >> 4) * 10000000)
+ ((bytes[3] & 0x0F) * 1000000)
+ ((bytes[2] >> 4) * 100000)
+ ((bytes[2] & 0x0F) * 10000)
+ ((bytes[1] >> 4) * 1000)
+ ((bytes[1] & 0x0F) * 100)
+ ((bytes[0] >> 4) * 10)
+ (bytes[0] & 0x0F);
}

2 Likes