I need to retrieve an integer number for the selected bit range (1-128) of a Mifare Classic 1k block (16 byte array). The number is represented binary with Big Endian.
I know how to do it manually with bitwise operations for a given range but i'm not able to make a method to handle it. I have tried to use java.util.BitSet also but it works with little-endian representation.
Actual code:
private int byteToInt(byte[] payload, int from, int to) {
BitSet bitSet = BitSet.valueOf(payload);
byte[] array = bitSet.get(from,to).toByteArray();
if(array.length == 0)
return 0;
else
return new BigInteger(array).intValue();
}
The byte array on the BigInteger constructor is assumed to be big-endian byte-ordered while BitSet.toByteArray() returns a little-endian byte array