I am new to Java. I have 8 bytes (or dlc
bytes ) of data in Java, which looks like this :
int dlc = 8;
byte[] myData = new byte[dlc];
Then I would like to get the value (start bit is 50, length is 2 bits) from myData
.
My idea is to convert myData
to bits, then find the value start from bits 50 and has a length of 2 bits, then convert the bits values to integer, is this method good ? if it's available, then how to do it in java ? if it's not, any ideas to pick out some part of value from bytes array ?
Solution : The solution is provided by @Zoyd
NOTE : BitSet.valueOf(Bytebuffer) is added from Android API 19! so if you have earlier API level, you cannot use valueOf() method. You can look at BitSet to and from integer/long