[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r1152 - /projects/zb4osgi/trunk/zigbee.common/src/main/java/it/cnr/isti/primitivetypes/util/Integers.java
scm-notify at zb4osgi.aaloa.org
scm-notify at zb4osgi.aaloa.org
Wed Jan 14 20:00:50 CET 2015
Author: giancarlo.riolo
Date: Wed Jan 14 20:00:50 2015
New Revision: 1152
Log:
UnsignedInteger40bit and UnsignedInteger48bit read works. refs #262
Modified:
projects/zb4osgi/trunk/zigbee.common/src/main/java/it/cnr/isti/primitivetypes/util/Integers.java
Modified: projects/zb4osgi/trunk/zigbee.common/src/main/java/it/cnr/isti/primitivetypes/util/Integers.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.common/src/main/java/it/cnr/isti/primitivetypes/util/Integers.java (original)
+++ projects/zb4osgi/trunk/zigbee.common/src/main/java/it/cnr/isti/primitivetypes/util/Integers.java Wed Jan 14 20:00:50 2015
@@ -426,12 +426,29 @@
}
public static long readLong(byte[] src, int pos, int size) {
- long val = 0;
- for (int i = size - 1; i > -1; i--) {
- val = (src[pos + i] & 0x00000000000000FF) + (val << 8);
-
- }
- return val;
+
+ byte[] resultByteArray = new byte[8];
+ ByteBuffer bb = ByteBuffer.wrap(src, pos, size);
+
+ for (int i = 0; i < size; i++)
+
+ {
+ byte temp = bb.get();
+ resultByteArray[size - i - 1] = temp;
+
+ }
+
+ ByteBuffer buffer = ByteBuffer.wrap(resultByteArray).order(
+ ByteOrder.LITTLE_ENDIAN);
+ return buffer.getLong();
+
+ //
+ // long val = 0;
+ // for (int i = size - 1; i > -1; i--) {
+ // val = (src[pos + i] & 0x00000000000000FF) + (val << 8);
+ //
+ // }
+ // return val;
}
@@ -455,10 +472,10 @@
int[] buffer = new int[3];
ByteBuffer b = ByteBuffer.wrap(src);
- buffer[0] = b.get(pos+2);
- buffer[1] = b.get(pos+1);
+ buffer[0] = b.get(pos + 2);
+ buffer[1] = b.get(pos + 1);
buffer[2] = b.get(pos);
-
+
int result = ((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8)) >> 8;
return result;
@@ -478,17 +495,15 @@
* @since 0.2.0
*/
public static int writeInt24bit(byte[] dest, int pos, int data) {
-
-
+
ByteBuffer b = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
- b.putInt(data);
- byte[] result = b.array();
-
-
- dest[pos] = (byte) ((result[1] & 0xFF0000) >> 16);
- dest[pos + 1] = (byte) ((result[2] & 0x00FF00) >> 8);
- dest[pos + 2] = (byte) ((result[3] & 0x0000FF));
-
+ b.putInt(data);
+ byte[] result = b.array();
+
+ dest[pos] = (byte) ((result[1] & 0xFF0000) >> 16);
+ dest[pos + 1] = (byte) ((result[2] & 0x00FF00) >> 8);
+ dest[pos + 2] = (byte) ((result[3] & 0x0000FF));
+
return 3;
}
More information about the Commit
mailing list