Fixed BinaryStruct bit shifting issue

This commit is contained in:
Ziver Koc 2016-05-12 23:00:28 +02:00
parent 3f21caa35b
commit 28d1f04246
3 changed files with 80 additions and 5 deletions

View file

@ -78,8 +78,7 @@ public class BinaryStructInputStream {
else {
byte[] valueData = new byte[(int) Math.ceil(field.getBitLength(struct) / 8.0)];
int fieldReadLength = 0; // How much we have read so far
int shiftBy = (dataBitIndex+1 + field.getBitLength(struct)) % 8;
int shiftBy = shiftBy(dataBitIndex, field.getBitLength(struct));
// Parse value
for (int valueDataIndex=valueData.length-1; valueDataIndex >= 0 ; --valueDataIndex) {
@ -102,5 +101,8 @@ public class BinaryStructInputStream {
return totalReadLength;
}
protected static int shiftBy(int bitIndex, int bitLength){
int shiftBy = (8 - ((7-bitIndex) + bitLength) % 8) % 8;
return shiftBy;
}
}