net.spy.util
Class BitArray

java.lang.Object
  extended by net.spy.util.BitArray

public class BitArray
extends java.lang.Object

An array of bits. The initial version of this is not intended to be efficient.


Constructor Summary
BitArray()
          Get an intance of BitArray.
BitArray(int size)
          Get an instance of BitArray with storage for a given number of bits.
BitArray(java.lang.String bitString)
          Get a BitArray by parsing a string.
 
Method Summary
 void add(boolean value)
          Add a bit.
 void addBits(int bitSet, int numBits)
          Add a set of bits from an integer.
 int getBits(int from, int number)
          Get a given number of bits from a given offset.
 int getLSBBits(int numBits)
          Get a given number of the least significant bits.
 int getMSBBits(int numBits)
          Get a given number of the most significant bits.
 void removeBits(int from, int howMany)
          Remove a specific number of bits from a specific location.
 void removeLSBBits(int howMany)
          Remove a give number of bits from the LSB side.
 void removeMSBBits(int howMany)
          Remove a give number of bits from the MSB side.
 int size()
          Get the number of bits remaining in the bit set.
 java.lang.String toString()
          String me.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitArray

public BitArray(int size)
Get an instance of BitArray with storage for a given number of bits.


BitArray

public BitArray()
Get an intance of BitArray.


BitArray

public BitArray(java.lang.String bitString)
Get a BitArray by parsing a string. The string must only contain the characters 0 (zero), 1 (one), and whitespace.

Parameters:
bitString - the string containing zeros and ones
Method Detail

add

public void add(boolean value)
Add a bit.

Parameters:
value - if true, add a one bit.

addBits

public void addBits(int bitSet,
                    int numBits)
Add a set of bits from an integer.

Parameters:
bitSet - the integer containing the bits
numBits - the number of bits to add.

removeMSBBits

public void removeMSBBits(int howMany)
Remove a give number of bits from the MSB side.

Parameters:
howMany - bits to remove

removeLSBBits

public void removeLSBBits(int howMany)
Remove a give number of bits from the LSB side.

Parameters:
howMany - bits to remove

removeBits

public void removeBits(int from,
                       int howMany)
Remove a specific number of bits from a specific location.

Parameters:
from - starting point
howMany - number of bits to remove.

getBits

public int getBits(int from,
                   int number)
Get a given number of bits from a given offset.

Parameters:
from - starting offset (from MSB side).
number - number of bits to retrieve
Returns:
an integer containing those bits
Throws:
java.lang.IllegalArgumentException - if number > 32
java.lang.IndexOutOfBoundsException - if the bit range would specify bits we don't have

getMSBBits

public int getMSBBits(int numBits)
Get a given number of the most significant bits.

Parameters:
numBits - number of bits to get
Returns:
an int representing the bits requested
Throws:
java.lang.IllegalArgumentException - if numBits greater than 31 or the number of bits remaining in the bit list

getLSBBits

public int getLSBBits(int numBits)
Get a given number of the least significant bits.

Parameters:
numBits - number of bits to get
Returns:
an int representing the bits requested
Throws:
java.lang.IllegalArgumentException - if numBits greater than 31 or the number of bits remaining in the bit list

size

public int size()
Get the number of bits remaining in the bit set.


toString

public java.lang.String toString()
String me.

Overrides:
toString in class java.lang.Object


Copyright © 1995-2006 SPY Internetworking. All Rights Reserved.