MIOB/EDF4J — pull request #1 by Wolfy42 (2012-11-11 08:20:55+00:00)
Title: byte-to-short conversion

byte-to-short
==========
I found a **bug** in the byte-to-short conversion in the EDFParser. I have changed the conversion from the existing-version to NIO, to that NIO has to deal with the conversion. This commit fixes the bug.

Following example shows the bug
===========================
Assume you have following bytes:
byte **b1** = (byte) 0b1001_1000;
System.out.println("b1: "+b1); // **"b1: -104"**
byte **b2** = (byte) 0b0000_1011;
System.out.println("b2: "+b2); // **"b2: 11"**
byte[] data = new byte[]{b1, b2};

The old conversion
--------------------------
short wrong_short = (short) (data[0] | data[1] * 256);
System.out.println("wrong_short: "+wrong_short); // **"wrong_short: -104"**

The corrected conversion
-----------------------------------
short correct_short = (short) ((data[0] & 0xFF) | (data[1] & 0xFF) * 256);
System.out.println("correct_short: "+correct_short); // **"correct_short: 2968"**

New version with NIO
-----------------------------
ByteBuffer dataBuffer = ByteBuffer.wrap(data);
dataBuffer.order(ByteOrder.LITTLE_ENDIAN);
short correct_short2 = dataBuffer.getShort();
System.out.println("correct_short2: "+correct_short2); // **"correct_short2: 2968"**