Java ByteBuffer to Float toFloat(ByteBuffer buffer)

Here you can find the source of toFloat(ByteBuffer buffer)

Description

to Float

License

Open Source License

Declaration

public static float toFloat(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static float toFloat(byte[] bytes) {
        return toFloat(ByteBuffer.wrap(bytes));
    }// w  w w. j  a v  a 2s  .  c o m

    public static float toFloat(ByteBuffer buffer) {
        return toByteBuffer(buffer, Float.BYTES).getFloat();
    }

    protected static ByteBuffer toByteBuffer(ByteBuffer buffer, int length) {
        if (length > buffer.remaining()) {
            return (ByteBuffer) ((ByteBuffer) ByteBuffer.allocate(length).position(length - buffer.remaining()))
                    .put(buffer.array()).rewind();
        } else {
            return buffer;
        }
    }
}

Related

  1. readFloat(ByteBuffer buffer)
  2. readFloatArray(ByteBuffer bb, int length)
  3. readFloats(final ByteBuffer bb, final int length)
  4. toFloat(AudioFormat format, ByteBuffer buf, float[] floatBuf)
  5. toFloat(ByteBuffer bytes)
  6. toFloat(ByteBuffer value)
  7. toFloat16BE(ByteBuffer buf, FloatBuffer out)
  8. toFloat24BE(ByteBuffer buf, float[] out)