-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
An 8 bit mask may be needed
Line 104:
return ((data[0] & 0xFF) << 8) + data[1];
should have an 8 bit mask & operation added:
return ((data[0] & 0xFF) << 8) + (data[1] & 0xff);
This eliminates sign extension issue.
This snippet I think exemplifies the fix:
byte[] data = new byte[2];
data[0] = (byte)0x80;
data[1] = (byte)0x80;
long incorrect = ((data[0] & 0xff) << 8) + (data[1]);
System.out.println("Incorrect " + String.format("0x%08X", incorrect));
long correct = ((data[0] & 0xff) << 8) + (data[1] & 0xff);
System.out.println("correct " + String.format("0x%08X", correct));
Output:
Incorrect 0x00007F80
correct 0x00008080
Metadata
Metadata
Assignees
Labels
No labels