FileDocCategorySizeDatePackage
Bits.javaAPI DocJava SE 6 API3540Tue Jun 10 00:25:32 BST 2008java.io

Bits

public class Bits extends Object
Utility methods for packing/unpacking primitive values in/out of byte arrays using big-endian byte ordering.

Fields Summary
Constructors Summary
Methods Summary
static booleangetBoolean(byte[] b, int off)

	return b[off] != 0;
    
static chargetChar(byte[] b, int off)

	return (char) (((b[off + 1] & 0xFF) << 0) + 
		       ((b[off + 0]) << 8));
    
static doublegetDouble(byte[] b, int off)

	long j = ((b[off + 7] & 0xFFL) << 0) +
		 ((b[off + 6] & 0xFFL) << 8) +
		 ((b[off + 5] & 0xFFL) << 16) +
		 ((b[off + 4] & 0xFFL) << 24) +
		 ((b[off + 3] & 0xFFL) << 32) +
		 ((b[off + 2] & 0xFFL) << 40) +
		 ((b[off + 1] & 0xFFL) << 48) +
		 (((long) b[off + 0]) << 56);
	return Double.longBitsToDouble(j);
    
static floatgetFloat(byte[] b, int off)

	int i = ((b[off + 3] & 0xFF) << 0) +
		((b[off + 2] & 0xFF) << 8) +
		((b[off + 1] & 0xFF) << 16) +
		((b[off + 0]) << 24);
	return Float.intBitsToFloat(i);
    
static intgetInt(byte[] b, int off)

	return ((b[off + 3] & 0xFF) << 0) +
	       ((b[off + 2] & 0xFF) << 8) +
	       ((b[off + 1] & 0xFF) << 16) +
	       ((b[off + 0]) << 24);
    
static longgetLong(byte[] b, int off)

	return ((b[off + 7] & 0xFFL) << 0) +
	       ((b[off + 6] & 0xFFL) << 8) +
	       ((b[off + 5] & 0xFFL) << 16) +
	       ((b[off + 4] & 0xFFL) << 24) +
	       ((b[off + 3] & 0xFFL) << 32) +
	       ((b[off + 2] & 0xFFL) << 40) +
	       ((b[off + 1] & 0xFFL) << 48) +
	       (((long) b[off + 0]) << 56);
    
static shortgetShort(byte[] b, int off)

	return (short) (((b[off + 1] & 0xFF) << 0) + 
			((b[off + 0]) << 8));
    
static voidputBoolean(byte[] b, int off, boolean val)

	b[off] = (byte) (val ? 1 : 0);
    
static voidputChar(byte[] b, int off, char val)

	b[off + 1] = (byte) (val >>> 0);
	b[off + 0] = (byte) (val >>> 8);
    
static voidputDouble(byte[] b, int off, double val)

	long j = Double.doubleToLongBits(val);
	b[off + 7] = (byte) (j >>> 0);
	b[off + 6] = (byte) (j >>> 8);
	b[off + 5] = (byte) (j >>> 16);
	b[off + 4] = (byte) (j >>> 24);
	b[off + 3] = (byte) (j >>> 32);
	b[off + 2] = (byte) (j >>> 40);
	b[off + 1] = (byte) (j >>> 48);
	b[off + 0] = (byte) (j >>> 56);
    
static voidputFloat(byte[] b, int off, float val)

	int i = Float.floatToIntBits(val);
	b[off + 3] = (byte) (i >>> 0);
	b[off + 2] = (byte) (i >>> 8);
	b[off + 1] = (byte) (i >>> 16);
	b[off + 0] = (byte) (i >>> 24);
    
static voidputInt(byte[] b, int off, int val)

	b[off + 3] = (byte) (val >>> 0);
	b[off + 2] = (byte) (val >>> 8);
	b[off + 1] = (byte) (val >>> 16);
	b[off + 0] = (byte) (val >>> 24);
    
static voidputLong(byte[] b, int off, long val)

	b[off + 7] = (byte) (val >>> 0);
	b[off + 6] = (byte) (val >>> 8);
	b[off + 5] = (byte) (val >>> 16);
	b[off + 4] = (byte) (val >>> 24);
	b[off + 3] = (byte) (val >>> 32);
	b[off + 2] = (byte) (val >>> 40);
	b[off + 1] = (byte) (val >>> 48);
	b[off + 0] = (byte) (val >>> 56);
    
static voidputShort(byte[] b, int off, short val)

	b[off + 1] = (byte) (val >>> 0);
	b[off + 0] = (byte) (val >>> 8);