Float to Byte Array Conversion

2

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?

    
asked by anonymous 17.08.2017 / 21:01

1 answer

2
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.

    
17.08.2017 / 21:04