How can I be converting from float
or integer (if possible) to a byte array in Java.
Let's say:
float x=180
Theoretically you would need to create 1 array of bytes with 2 positions. Is there any way to 'automate' this?
How can I be converting from float
or integer (if possible) to a byte array in Java.
Let's say:
float x=180
Theoretically you would need to create 1 array of bytes with 2 positions. Is there any way to 'automate' this?
ByteBuffer.allocate(4).putFloat(180).array();
This would create a array with 4 positions. The bytes alone will not serve much.
Documentation . It shows you the methods to deal with the other types you may want. What this class does is just treat the data as if it were just bytes.