Float to Byte Array conversion

Asked

Viewed 61 times

3

How can I be performing the conversion of float or integer (if possible) for a array byte in Java.

Say:

float x=180

Theoretically you would need to create 1 array 2 position bytes. Is there any way to 'automate' this?

1 answer

2


ByteBuffer.allocate(4).putFloat(180).array();

I put in the Github for future reference.

This would create a array with 4 positions. Bytes alone will not do much good.

Documentation. There it shows the methods to deal with the other types you might want. What this class does is just treat the data as if it were just bytes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.