com.amx.duet.tools.lang
Class Bits

java.lang.Object
  extended bycom.amx.duet.tools.lang.Bits

public class Bits
extends java.lang.Object

Utility methods for packing/unpacking primitive values in/out of byte arrays using big-endian byte ordering.


Constructor Summary
Bits()
           
 
Method Summary
static byte[] flipBytes(byte[] b)
          Changes the order of a byte array for endianness.
static boolean getBoolean(byte[] b, int off)
          Method for unpacking boolean values from byte arrays starting at given offsets.
static char getChar(byte[] b, int off)
          Method for unpacking character values from byte arrays starting at given offsets.
static double getDouble(byte[] b, int off)
          Method for unpacking double values from byte arrays starting at given offsets.
static float getFloat(byte[] b, int off)
          Method for unpacking float values from byte arrays starting at given offsets.
static int getInt(byte[] b, int off)
          Method for unpacking integer values from byte arrays starting at given offsets.
static long getLong(byte[] b, int off)
          Method for unpacking long values from byte arrays starting at given offsets.
static short getShort(byte[] b, int off)
          Method for unpacking short values from byte arrays starting at given offsets.
static boolean isBitSet(int value, int pos)
          Checks to see if the bit position in an 8 bit value is set.
static void putBoolean(byte[] b, int off, boolean val)
          Method for packing boolean values into byte arrays starting at given offsets.
static void putChar(byte[] b, int off, char val)
          Method for packing character values into byte arrays starting at given offsets.
static void putDouble(byte[] b, int off, double val)
          Method for packing double values into byte arrays starting at given offsets.
static void putFloat(byte[] b, int off, float val)
          Method for packing float values into byte arrays starting at given offsets.
static void putInt(byte[] b, int off, int val)
          Method for packing integer values into byte arrays starting at given offsets.
static void putLong(byte[] b, int off, long val)
          Method for packing long values into byte arrays starting at given offsets.
static void putShort(byte[] b, int off, short val)
          Method for packing short values into byte arrays starting at given offsets.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bits

public Bits()
Method Detail

getBoolean

public static final boolean getBoolean(byte[] b,
                                       int off)
Method for unpacking boolean values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

getChar

public static final char getChar(byte[] b,
                                 int off)
Method for unpacking character values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

getShort

public static final short getShort(byte[] b,
                                   int off)
Method for unpacking short values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

getInt

public static final int getInt(byte[] b,
                               int off)
Method for unpacking integer values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

getFloat

public static final float getFloat(byte[] b,
                                   int off)
Method for unpacking float values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

getLong

public static final long getLong(byte[] b,
                                 int off)
Method for unpacking long values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

getDouble

public static final double getDouble(byte[] b,
                                     int off)
Method for unpacking double values from byte arrays starting at given offsets.

Parameters:
b -
off -
Returns:

putBoolean

public static final void putBoolean(byte[] b,
                                    int off,
                                    boolean val)
Method for packing boolean values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

putChar

public static final void putChar(byte[] b,
                                 int off,
                                 char val)
Method for packing character values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

putShort

public static final void putShort(byte[] b,
                                  int off,
                                  short val)
Method for packing short values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

putInt

public static final void putInt(byte[] b,
                                int off,
                                int val)
Method for packing integer values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

putFloat

public static final void putFloat(byte[] b,
                                  int off,
                                  float val)
Method for packing float values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

putLong

public static final void putLong(byte[] b,
                                 int off,
                                 long val)
Method for packing long values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

putDouble

public static final void putDouble(byte[] b,
                                   int off,
                                   double val)
Method for packing double values into byte arrays starting at given offsets.

Parameters:
b -
off -
val -

isBitSet

public static final boolean isBitSet(int value,
                                     int pos)
Checks to see if the bit position in an 8 bit value is set. Position starts at 0 (the lowest bit) and ends a 7 (the 8th bit).

Parameters:
value - 8 bit value
pos - 0-7 (bytes 1-8 respectively)
Returns:
true if the bit is set; false otherwise.

flipBytes

public static final byte[] flipBytes(byte[] b)
Changes the order of a byte array for endianness.

Parameters:
b - byte array to flip.
Returns:
the byte array in reverse order.


Copyright © 2008 AMX LLC. All Rights Reserved.