|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--SSF.OS.BGP4.Util.BitString
This class implements a binary string. It is sort of a cross between a boolean array and a java.util.BitSet. It has the fast array access property of a boolean array, but the nice, intuitive interface of BitSet. (Thinking about a boolean array as a sequence of bits can get annoying.) The only bad thing is that an object of this type is not nearly as space-efficient as that of a BitSet.
| Constructor Summary | |
BitString(boolean[] b)
Constructs a BitString from a boolean array. |
|
BitString(int val,
int size)
Converts an integer into an array of bits. |
|
BitString(long val,
int size)
Converts a long integer into an array of bits. |
|
| Method Summary | |
void |
and(BitString bs)
Performs a logical AND between this BitString and the given BitString and assigns the results to this BitString. |
static BitString |
and(BitString bs1,
BitString bs2)
Performs a logical AND between this two given BitStrings and returns the result in a new BitString. |
boolean |
bgetlr(int bitnum)
Returns the value of the given bit as a boolean. |
boolean |
bgetrl(int bitnum)
Return the value of the given bit as a boolean. |
void |
clear(int bitnum)
Sets the value of the given bit to zero. |
int |
getlr(int bitnum)
Returns the value of the given bit as an integer. |
int |
getrl(int bitnum)
Returns the value of the given bit as an integer. |
void |
not()
Performs a logical NOT operation on this BitString and assigns the results to this BitString. |
static BitString |
not(BitString bs)
Performs a logical NOT on this BitStrings and returns the result in a new BitString. |
void |
or(BitString bs)
Performs a logical OR between this BitString and the given BitString and assigns the results to this BitString. |
static BitString |
or(BitString bs1,
BitString bs2)
Performs a logical OR between this two given BitStrings and returns the result in a new BitString. |
BitString |
revSubstring(int s)
Returns a substring of the reverse of the bit string given one index and assuming the end of the string as the other index. |
BitString |
revSubstring(int s,
int e)
Returns a substring of the reverse of the bit string given two indices. |
void |
set(int bitnum)
Sets the value of the given bit to one. |
int |
size()
Returns the length of the string (the number of bits). |
BitString |
substring(int s)
Returns a substring of the bit string given one index and assuming the end of the string as the other index. |
BitString |
substring(int s,
int e)
Returns a substring of the bit string given two indices. |
java.lang.String |
toString()
Prints out the bit string. |
void |
xor(BitString bs)
Performs a logical XOR between this BitString and the given BitString and assigns the results to this BitString. |
static BitString |
xor(BitString bs1,
BitString bs2)
Performs a logical XOR between this two given BitStrings and returns the result in a new BitString. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public BitString(int val,
int size)
EXAMPLE: BitString(23,8) is called. Mentally we might picture the integer 23 as the bit string 10111 (with any number of 0's optionally prepended). The size parameter tells us that eight of the bits are significant to us, so for convenience we'll represent 23 as 00010111. A bit array 'b' constructed from this input would be b={1,1,1,0,1,0,0,0}, or b[0]=b[1]=b[2]=b[4]=1 and b[3]=b[5]=b[6]=b[7]=0, where 0=false and 1=true.
The standard printed representation of the array has the most
significant bits on the left and the least significant bits on the right.
The array representation has each index corresponding to the significance
of the bit it represents. In other words, the element 0 corresponds to the
least significant bit, element 1 corresponds to the second least
significant bit, and so on through element size-1, which
represents the most significant bit.
val - The integer value of the bit string.size - The number of bits in the bit string.BitString(long,int)
public BitString(long val,
int size)
val - The integer value of the bit string.size - The number of bits in the bit string.BitString(int,int)public BitString(boolean[] b)
b - A boolean array representing a bit string.| Method Detail |
public void set(int bitnum)
bitnum - The index of a bit in the string.public void clear(int bitnum)
bitnum - The index of a bit in the string.public int getlr(int bitnum)
bitnum - The index of a bit in the string.
public boolean bgetlr(int bitnum)
bitnum - The index of a bit in the string.
public int getrl(int bitnum)
bitnum - The index of a bit in the string.
public boolean bgetrl(int bitnum)
bitnum - The index of a bit in the string.
public int size()
public void and(BitString bs)
bs - The bit string to AND with.public void or(BitString bs)
bs - The bit string to OR with.public void xor(BitString bs)
bs - The bit string to XOR with.public void not()
public static BitString and(BitString bs1,
BitString bs2)
bs1 - The first of two bit strings perform an AND upon.bs2 - The second of two bit strings perform an AND upon.
public static BitString or(BitString bs1,
BitString bs2)
bs1 - The first of two bit strings perform an OR upon.bs2 - The second of two bit strings perform an OR upon.
public static BitString not(BitString bs)
bs - A bit string to perform a NOT upon.
public static BitString xor(BitString bs1,
BitString bs2)
bs1 - The first of two bit strings perform an XOR upon.bs2 - The second of two bit strings perform an XOR upon.
public BitString substring(int s,
int e)
s - The starting index for the substring.e - The ending index for the substring.
public BitString substring(int s)
s - The starting index for the substring.
public BitString revSubstring(int s,
int e)
s - The starting index for the substring.e - The ending index for the substring.
public BitString revSubstring(int s)
s - The starting index for the substring.
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||