Answer the question
In order to leave comments, you need to log in
Float back to bytes how to implement?
The code with which I get the value from the byte float:
byte[] response = new byte[]{-39, 118, -98, 60};
// Получаем коефециент
int asInt = (response[0] & 0xFF)
| ((response[1] & 0xFF) << 8)
| ((response[2] & 0xFF) << 16)
| ((response[3] & 0xFF) << 24);
float asFloat = Float.intBitsToFloat(asInt);
At the output I get: The 0.01934378
Answer the question
In order to leave comments, you need to log in
Tried water like this:
byte[] b = ByteBuffer.allocate(4).putFloat(asFloat).array();
But at the output I get in reverse order [60, -98, 118, -39]
byte[] gf = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putFloat(asFloat).array();
System.out.println("Значение обратно" + Arrays.toString(gf));
And everything works fine!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question