[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r1150 - in /projects/zb4osgi/trunk/zigbee.common/src: main/java/it/cnr/isti/primitivetypes/util/Integers.java test/java/it/cnr/isti/primitivetypes/util/IntegersTest.java

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Wed Jan 14 11:42:46 CET 2015


Author: giancarlo.riolo
Date: Wed Jan 14 11:42:45 2015
New Revision: 1150

Log:
Integers.ReadLong Fixed.

Modified:
    projects/zb4osgi/trunk/zigbee.common/src/main/java/it/cnr/isti/primitivetypes/util/Integers.java
    projects/zb4osgi/trunk/zigbee.common/src/test/java/it/cnr/isti/primitivetypes/util/IntegersTest.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 11:42:45 2015
@@ -433,21 +433,16 @@
 
 	public static long readLong(byte[] src, int pos, int size) {
 		long val = 0;
-		for (int i = 0; i < size; i++) {
+		for (int i = size - 1; i > -1; i--) {
 			val = (src[pos + i] & 0x00000000000000FF) + (val << 8);
+
 		}
 		return val;
+
 	}
 
 	public static long readLong(byte[] src, int pos) {
-		return ((long) (src[pos] & 0x00000000000000FF) << 56)
-				+ ((long) (src[pos + 1] & 0x00000000000000FF) << 48)
-				+ ((long) (src[pos + 2] & 0x00000000000000FF) << 40)
-				+ ((long) (src[pos + 3] & 0x00000000000000FF) << 32)
-				+ ((long) (src[pos + 4] & 0x00000000000000FF) << 24)
-				+ ((long) (src[pos + 5] & 0x00000000000000FF) << 16)
-				+ ((long) (src[pos + 6] & 0x00000000000000FF) << 8)
-				+ ((long) (src[pos + 7] & 0x00000000000000FF));
+		return readLong(src, pos, 8);
 
 	}
 

Modified: projects/zb4osgi/trunk/zigbee.common/src/test/java/it/cnr/isti/primitivetypes/util/IntegersTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.common/src/test/java/it/cnr/isti/primitivetypes/util/IntegersTest.java	(original)
+++ projects/zb4osgi/trunk/zigbee.common/src/test/java/it/cnr/isti/primitivetypes/util/IntegersTest.java	Wed Jan 14 11:42:45 2015
@@ -318,9 +318,9 @@
 			idx += Integers.writeLong(buffer, idx, expected[i], 8);
 		}
 		for (int i = 0; i < expected.length; i++) {
-			// TODO:Debug
-			// long value = Integers.readLong(buffer, i * 8);
-			// assertEquals("failed to write with K=8", expected[i], value);
+			
+		 long value = Integers.readLong(buffer, i * 8);
+		 assertEquals("failed to write with K=8", expected[i], value);
 		}
 
 		for (int k = MAX_SIZE; k < MIN_SIZE; k--) {
@@ -506,13 +506,7 @@
 		// checking full 8 bytes write
 		Integers.writeLong(test64, 0, l, 8);
 		assertArrayEquals(expected, test64);
-
-		// checking partial writes
-		// byte[] test = new byte[1];
-		// byte[] partial = new byte[]{expected[7]};
-		// Integers.writeLong(test, 0, l, 1);
-		// assertArrayEquals(partial, test);
-
+		
 		// checking partial write
 		for (int i = 1; i <= 8; i++) {
 			byte[] test = new byte[i];




More information about the Commit mailing list