I have a 14 bit, two's complement value being sent to my java application form a bluetooth device in the form of a byte array.
I am unable to change the format of the data sent from the bluetooth device.
How do I get this value into an Integer or Short and maintain the sign?
A few things I have tried are
Short x = ByteBuffer.wrap(value).getShort();
Integer x = (short)(value[3] & 0xff) | (short)((value[2] << 8) & 0xff00);
The problem I think I encounter with the above code is when I receive a negative number, for example
-8192 (in two's complement 10 0000 0000 0000)
Because the receiving data type is 16 bits it expects the bit that negates the value to be 16 along but seen as what it actually receives is
0010 0000 0000 0000
It considers this 8192 and not -8192.