Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Fix java short and ushort conversions using byte arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
MB3hel committed Feb 24, 2019
1 parent 30cdd88 commit 9dce3a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ allprojects {

def mavenrepo = rootProject.projectDir.toString() + "/build/maven"
def vendordepsdir = rootProject.projectDir.toString() + "/build/vendordeps"
def libraryVersion = "2019-r1"
def libraryVersion = "2019-r2"
def publishGroupId = 'com.github.juchong'

subprojects{
Expand Down
10 changes: 5 additions & 5 deletions java/src/main/java/com/analog/adis16448/frc/ADIS16448_IMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ static int ToUShort(ByteBuffer buf) {
return (buf.getShort(0)) & 0xFFFF;
}
static int ToUShort(byte[] buf) {
return buf[0] << 8 & buf[1];
return (buf[0] << 8 | buf[1]) & 0xFFFF;
}
static int ToUShort(int... data) {
ByteBuffer buf = ByteBuffer.allocate(data.length);
for(int d : data) {
buf.put((byte)d);
byte[] buf = new byte[data.length];
for(int i = 0; i < data.length; ++i) {
buf[i] = (byte)data[i];
}
return ToUShort(buf);
}
Expand All @@ -394,7 +394,7 @@ public static long ToULong(int sint) {
}

private static int ToShort(int... buf) {
return (short)(((short)buf[0]) << 8 | buf[1]);
return (buf[0] << 8 | buf[1]);
}
static int ToShort(ByteBuffer buf) {
return ToShort(buf.get(0), buf.get(1));
Expand Down

0 comments on commit 9dce3a0

Please sign in to comment.