RADIUS Client API (V3)

com.theorem.radius3.radutil
Class BitArray

Object
  extended byBitArray

public class BitArray
extends Object

Class to handle bit operations.


Field Summary
static int BYTE_SIZE
          Bit size of a byte 8.
static int INT_SIZE
          Bit size of an integer 32.
 
Constructor Summary
BitArray(byte[] b)
          Constructor initialized by byte array,
BitArray(byte[] b, int maxBytes)
          Constructor initialized by byte array,
BitArray(int length)
          Constructor with maximum length in bytes for bit array.
 
Method Summary
 int cardinality()
          Count bits (for parity).
 void clear()
          Clear all bits.
 void clear(int n)
          Clear a bit.
 void clear(int fromIndex, int toIndex)
          Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to false.
static int concoctInt(byte[] b, int start)
          Converts 4 bytes of a byte array into an int from the starting position.
 byte[] extractBytes(int start, int length)
          Extract some bits at a particular position.
 int extractInt(int start, int length)
          Extract some bits at a particular position.
 long extractLong(int start, int length)
          Extract some bits at a particular position.
 boolean get(int n)
          Get a bit value.
 int getMaximumBits()
          Get the number of bits in the array.
 boolean isEmpty()
          Returns true if this BitArray contains no bits that are set to true.
 int length()
          Get the length of the BitArray.
static void main(String[] a)
          Test of BitArray.
 int nextClearBit(int posn)
          Find the position of the next clear bit.
 int nextSetBit(int posn)
          Find the position of the next set bit.
 void reset()
          Clear all bits.
 void set(int n)
          Set a bit at a position.
 void set(int n, boolean v)
          Set a bit at a position depending on the boolean value..
 byte[] toByteArray()
          Return the bit array as a byte array.
 String toHexString()
          Convert to hex string
 String toString()
          Display as binary string.
 boolean xor()
          Xor all bits (parity).
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INT_SIZE

public static final int INT_SIZE
Bit size of an integer 32.

See Also:
Constant Field Values

BYTE_SIZE

public static final int BYTE_SIZE
Bit size of a byte 8.

See Also:
Constant Field Values
Constructor Detail

BitArray

public BitArray(int length)
Constructor with maximum length in bytes for bit array.

Parameters:
length - Number of bits in array.

BitArray

public BitArray(byte[] b)
Constructor initialized by byte array,

Parameters:
b - Byte array.

BitArray

public BitArray(byte[] b,
                int maxBytes)
Constructor initialized by byte array,

Parameters:
b - Byte array.
maxBytes - maximum number of bytes.
Method Detail

set

public void set(int n)
Set a bit at a position.

Parameters:
n - bit position.

set

public void set(int n,
                boolean v)
Set a bit at a position depending on the boolean value..

Parameters:
n - bit position.
v - boolean value to set.

get

public boolean get(int n)
Get a bit value.

Parameters:
n - bit position.
Returns:
true if the bit is on, false otherwise.

cardinality

public int cardinality()
Count bits (for parity).

Returns:
number of bits set.

xor

public boolean xor()
Xor all bits (parity).

Returns:
true if the XOR of all bits is true, false otherwise.

extractInt

public int extractInt(int start,
                      int length)
Extract some bits at a particular position.

Parameters:
start - Start position.
length - Number of bits to extract (limited to 32 bits for an int value).

extractLong

public long extractLong(int start,
                        int length)
Extract some bits at a particular position.

Parameters:
start - Start position.
length - Number of bits to extract (limited to 64 bits for a long value).

extractBytes

public byte[] extractBytes(int start,
                           int length)
Extract some bits at a particular position.

Parameters:
start - Start position.
length - Number of bits to extract (limited to 64 bits for a long value).

clear

public void clear(int n)
Clear a bit.

Parameters:
n - bit position.

clear

public void clear(int fromIndex,
                  int toIndex)
Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to false.

Parameters:
fromIndex - Starting index.
toIndex - Ending index.

isEmpty

public boolean isEmpty()
Returns true if this BitArray contains no bits that are set to true.


clear

public void clear()
Clear all bits.


reset

public void reset()
Clear all bits.


toByteArray

public byte[] toByteArray()
Return the bit array as a byte array. Padding will be added as necessary.

Returns:
byte array.

toHexString

public String toHexString()
Convert to hex string

Returns:
string.

toString

public String toString()
Display as binary string.

Returns:
string.

getMaximumBits

public int getMaximumBits()
Get the number of bits in the array.

Returns:
number of bits in the bit array.

main

public static void main(String[] a)
Test of BitArray.


concoctInt

public static int concoctInt(byte[] b,
                             int start)
Converts 4 bytes of a byte array into an int from the starting position.

Parameters:
b - buffer.
start - postion to extract data
Returns:
int value

nextClearBit

public int nextClearBit(int posn)
Find the position of the next clear bit.

Parameters:
posn - Position to start searching for the next clear bit.
Returns:
the position of the next clear bit or one past the number of existing bits if there are no clear bits.

nextSetBit

public int nextSetBit(int posn)
Find the position of the next set bit.

Parameters:
posn - Position to start searching for the next set bit.
Returns:
the position of the next set bit or one past the number of existing bits if there are no set bits.

length

public int length()
Get the length of the BitArray.

Returns:
length of BitArray.

RADIUS Client API (V3)

Submit a bug report or feature request

Copyright 1998-2002 AXL Software. PO Box 97, Viola, Delaware 19979, U.S.A. All Rights Reserved.