Issue #302 has been reported by Philipp Buluschek.
----------------------------------------
Bug #302: ByteUtils.convertMultiByteToLong(byte[]) is wrong
http://zb4o.aaloa.org/redmine/issues/302
Author: Philipp Buluschek
Status: New
Priority: Normal
Assignee:
Category:
Target version:
Has a patch: No
Has license agreement signed: No
The conversion method from a @byte[]@ to a @long@ in ByteUtils is wrong.
See: @ByteUtils.convertMultiByteToLong(byte[])@.
Test case:
<pre>
@Test
public void testConvertMultibyteToLong() throws Exception {
byte[] d = new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
long l = ByteUtils.convertMultiByteToLong(d);
assertEquals(1L, l); // fails with value 256
d = new byte[]{0x01,0x23,0x45,0x67,(byte) 0x89,(byte) 0xAB,(byte) 0xCD,(byte)
0xEF};
long long1 = ByteUtils.convertMultiByteToLong(d);
assertEquals(81985529216486895L, long1);
}
</pre>
A possible correct implementation uses:
<pre>
long val = bytes[0] & 0xFF;
for (int i = 1; i < bytes.length; i++) {
val = val << 8;
val += bytes[i] & 0xFF;
}
return val;
</pre>
--
DO NOT ANSWER TO THIS E-MAIL ADDRESS, NO ONE WILL READ IT. PLEASE WRITE TO
[email protected]
ZigBee 4 OSGi - Redmine E-Mail Notificatioon
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://zb4o.aaloa.org/redmine
_______________________________________________
Dev mailing list
[email protected]
http://zb4osgi.aaloa.org/mailman/listinfo/dev