List of usage examples for java.nio ByteBuffer asFloatBuffer
public abstract FloatBuffer asFloatBuffer();
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(99471142); System.out.println(bb.getFloat()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(994.7F); System.out.println(bb.getFloat(0)); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(994.7F); System.out.println(bb.getFloat()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(994.7F); bb.rewind();/*from w w w . j a v a 2 s . c o m*/ System.out.println(bb.getFloat()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(15); FloatBuffer fbuf = buf.asFloatBuffer(); }
From source file:Buffers.java
public static void main(String[] args) { try {/*w w w . j a v a 2 s .c om*/ float[] floats = { 6.61E-39F, 9.918385E-39F }; ByteBuffer bb = ByteBuffer.allocate(floats.length * 4); FloatBuffer fb = bb.asFloatBuffer(); fb.put(floats); CharBuffer cb = bb.asCharBuffer(); System.out.println(cb.toString()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asIntBuffer().put(99471142);//w w w .j av a 2 s . c o m System.out.println(bb.getInt()); bb = ByteBuffer.allocate(BSIZE); bb.asLongBuffer().put(99472342341142L); System.out.println(bb.getLong()); bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(99471142); System.out.println(bb.getFloat()); bb = ByteBuffer.allocate(BSIZE); bb.asDoubleBuffer().put(99471142); System.out.println(bb.getDouble()); }
From source file:GetData.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); // Allocation automatically zeroes the ByteBuffer: int i = 0;// w w w . ja v a 2s.c om while (i++ < bb.limit()) if (bb.get() != 0) System.out.println("nonzero"); System.out.println("i = " + i); bb.rewind(); // Store and read a char array: bb.asCharBuffer().put("Howdy!"); char c; while ((c = bb.getChar()) != 0) System.out.print(c + " "); System.out.println(); bb.rewind(); // Store and read a short: bb.asShortBuffer().put((short) 471142); System.out.println(bb.getShort()); bb.rewind(); // Store and read an int: bb.asIntBuffer().put(99471142); System.out.println(bb.getInt()); bb.rewind(); // Store and read a long: bb.asLongBuffer().put(99471142); System.out.println(bb.getLong()); bb.rewind(); // Store and read a float: bb.asFloatBuffer().put(99471142); System.out.println(bb.getFloat()); bb.rewind(); // Store and read a double: bb.asDoubleBuffer().put(99471142); System.out.println(bb.getDouble()); bb.rewind(); }
From source file:Main.java
public static byte[] floatsToBytes(float[] floats) { ByteBuffer byteBuffer = ByteBuffer.allocate(floats.length * 4); byteBuffer.asFloatBuffer().put(floats); return byteBuffer.array(); }
From source file:Main.java
public static float toFloatEx(byte[] b, int pos) { try {/*www. j a v a 2s.c o m*/ byte[] byteTmp = new byte[4]; for (int i = 0; i < 4; i++) { byteTmp[i] = b[pos + i]; } ByteBuffer bb = ByteBuffer.wrap(byteTmp); FloatBuffer fb = bb.asFloatBuffer(); return fb.get(); } catch (Exception e) { e.printStackTrace(); return 0.0f; } }