Java ByteBuffer store float type value

Description

Java ByteBuffer store float type value



import java.nio.ByteBuffer;

public class Main {
    public static final void writeFloat(ByteBuffer buffer, float f) {
        writeInt(buffer, Float.floatToIntBits(f));
    }/*from  w  w w. j  ava  2 s.  co m*/

    public static final void writeInt(ByteBuffer buffer, int i) {
        buffer.put((byte) (i & 0xff));
        buffer.put((byte) (i >>> 8));
        buffer.put((byte) (i >>> 16));
        buffer.put((byte) (i >>> 24));
    }
}



PreviousNext

Related