I have an Android application with the BLE module. the BLE device is giving byte array with 24 bytes. Each byte has a separate meaning. In the byte array, 10 and 11 items are voltage and its a combination of 16-bit representation.
eg: I am getting the 11 item as 0 and 12 item as 3. So I want to convert it to a single 16-bit representation value. Also, I want to get this as a float value, because I need to display the voltage as a float value in the UI. I don't know anyone already ask this question. If anyone know the formulae for 8 bit to 16-bit representation please add the formulae.Answer1:
Try this it may help you
short yourinteger16 = (short)(((bytes & 0xFF) << 8) | (bytes & 0xFF));Answer2:
short yourinteger16 = ((short) ((bytes & 0xff) | (bytes << 8)));
-TESTED- This is the general form for both positive and negative numbers