things are turning nasty
This commit is contained in:
parent
fa68d54687
commit
29a83d222a
|
@ -99,6 +99,7 @@ public class DbcField {
|
|||
public static int getBitRange(byte[] data, int bitIndex, int bitWidth, boolean isBigEndian) {
|
||||
if (bitIndex < 0)
|
||||
throw new IllegalArgumentException("Huh? " + bitIndex + " " + bitWidth);
|
||||
|
||||
int byteIndex = bitIndex >> 3;
|
||||
int shift = bitIndex - byteIndex * 8;
|
||||
if (byteIndex >= data.length)
|
||||
|
|
|
@ -24,8 +24,11 @@ public class GetValueFromTrcTest {
|
|||
|
||||
@Test
|
||||
public void testBigEndian() {
|
||||
byte[] rpm = {(byte) 0x70, 0x04, 0x1F};
|
||||
assertEquals(0x41f, DbcField.getBitRange(rpm, 16, 16, true));
|
||||
|
||||
byte[] data = {(byte) 0xAB, 0x56, 0x34};
|
||||
// hmmm
|
||||
|
||||
assertEquals(0x56AB, DbcField.getBitRange(data, 0, 16, false));
|
||||
assertEquals(0xAB56, DbcField.getBitRange(data, 8, 16, true));
|
||||
|
||||
|
|
Loading…
Reference in New Issue