Java by API/java.nio/FloatBuffer — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
FloatBuffer: get()
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class Main {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
System.out.println("Float Buffer");
while (fb.hasRemaining())
System.out.println(fb.position() + " -> " + fb.get());
}
}
FloatBuffer: hasRemaining()
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class Main {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
System.out.println("Float Buffer");
while (fb.hasRemaining())
System.out.println(fb.position() + " -> " + fb.get());
}
}
FloatBuffer: position()
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class Main {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
System.out.println("Float Buffer");
while (fb.hasRemaining())
System.out.println(fb.position() + " -> " + fb.get());
}
}
FloatBuffer: put(float f)
import java.nio.ByteBuffer;
public class Main {
private static final int BSIZE = 1024;
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.allocate(BSIZE);
bb.asFloatBuffer().put(99471142);
System.out.println(bb.getFloat());
}
}