0

So I have this byte array:

// tvltmp[0] = 0x21;
// tvltmp[1] = 0x63;
// tvltmp[2] = 0x84;

And this represents "12:36:48" in what I called "reversed endianess BDC".

To decode that, one just have to follow this manual:

      LSD | MSD 
byte0    2|1    Hour
byte1    6|3    Minute
byte2    8|4    Second

LSD = Least Significant Digit
MSD = Most Significant Digit

Which is fair enough.

I just have no clue how to get that done in Java.

Basically, how do I invert the endianess of a byte array (assuming that this is indeed a endianess issue)?

And how do I get the proper values from BCD bytes in java? I mean if I do the typical & 0xFF things will obviously go wrong...

Thanks,

filippo
  • 5,583
  • 13
  • 50
  • 72

1 Answers1

1

Something like this:

public int fromReverseBCD(byte b) {
    return 10 * (b & 0xf) + ((b >>> 4) & 0xf);
}
axtavt
  • 239,438
  • 41
  • 511
  • 482