|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--cryptix.util.math.BigRegister
Utility class to manage a large bit-register of a given size as a mutable object.
The bits are indexed from 0 (rightmost) to size
- 1, (leftmost) where size
is this register's
designated (at instantiation time) bit capacity.
Copyright © 1995-1997
Systemics Ltd on behalf of the
Cryptix Development Team.
All rights reserved.
$Revision: 1.2 $
Field Summary | |
static int |
MAXIMUM_SIZE
Maximum allowed number of bits in a BigRegister object. |
Constructor Summary | |
BigRegister(int size)
Instantiate a BigRegister of a given size
with all its bits set to zeroes. |
Method Summary | |
void |
and(BigRegister source)
Compute this &= source . |
void |
andNot(BigRegister source)
Compute this &= ~source . |
void |
atRandom()
Fill this BigRegister object with random data
generated from the default source. |
void |
atRandom(java.security.SecureRandom source)
Fill this BigRegister object with random data
generated from a designated source. |
int |
byteValue()
Return the rightmost byte value in this BigRegister . |
void |
clearBit(int n)
Set the bit at the designated position to 0; ie. clear it. |
java.lang.Object |
clone()
Return a reference to a duplicate of this . |
int |
compareTo(BigRegister x)
Compare this BigRegister 's contents to that of the
argument, returning -1, 0 or 1 for less than, equal to, or greater
than comparison result. |
int |
countSetBits()
Return the number of bits set (to 1) in this . |
void |
flipBit(int n)
Flip the value of the bit at the designated position. |
int |
getBit(int n)
Return 1 or 0 if the designated bit was set or cleared respectively. |
long |
getBits(int n,
int count)
Return count bits starting at offset n
framed in a long , right justified and left padded
with binary zeroes. |
int |
getSize()
Return the size of this object as
specified at its instantiation time. |
int |
highestSetBit()
Return the index of the leftmost non-zero bit in this . |
int |
intValue()
Return the rightmost 32-bit value in this BigRegister
as an int . |
void |
invertOrder()
Invert the bit order of the current contents of this . |
boolean |
isSameValue(BigRegister x)
Return true if the parameters of the BigRegister x ( size and bits ) are equal to this one;
false otherwise.
|
void |
load(BigRegister source)
Copy the argument's value into this . |
void |
load(byte[] source)
Copy the bit values from a byte array into this .
|
long |
longValue()
Return the rightmost 64-bit value in this BigRegister
as a long . |
int |
lowestSetBit()
Return the index of the rightmost non-zero bit in this . |
void |
not()
Compute this = ~this . |
void |
or(BigRegister source)
Compute this |= source . |
void |
reset()
Reset to zeroes all this BigRegister 's bits. |
void |
rotateLeft(int n)
Circular left shift over the size of this
register.
|
void |
rotateRight(int n)
Circular right shift over the size of this
register.
|
void |
setBit(int n)
Set the bit at the designated position to 1. |
void |
setBits(int n,
int count,
long value)
Set count bits starting at offset n
to a given value . |
void |
shiftLeft(int n)
Execute a left shift of this BigRegister 's contents
by a given number of bit positions. |
void |
shiftRight(int n)
Execute a right shift of this BigRegister 's contents
by a given number of bit positions. |
boolean |
testBit(int n)
Return true if the designated bit is set or false otherwise. |
byte[] |
toByteArray()
Return a copy of this BigRegister 's contents in a
byte array with the LSB at index position 0. |
java.lang.String |
toString()
Return a formatted String representation of the binary
contents of this . |
BigRegister |
valueOf(long n)
Return a BigRegister , of the same size
as this set to the specified value. |
void |
xor(BigRegister source)
Compute this ^= source . |
Methods inherited from class java.lang.Object |
|
Field Detail |
public static final int MAXIMUM_SIZE
BigRegister
object.Constructor Detail |
public BigRegister(int size)
BigRegister
of a given size
with all its bits set to zeroes.size
- Number of meaningful bits in this
object.java.lang.IllegalArgumentException
- If the argument is less than
2 or greater than the maximum allowed value.MAXIMUM_SIZE
Method Detail |
public java.lang.Object clone()
this
.clone
in class java.lang.Object
public void and(BigRegister source)
this &= source
.java.lang.IllegalArgumentException
- If the argument is of
different size
than this
.public void andNot(BigRegister source)
this &= ~source
.java.lang.IllegalArgumentException
- If the argument is of
different size
than this
.public void or(BigRegister source)
this |= source
.java.lang.IllegalArgumentException
- If the argument is of
different size
than this
.public void not()
this = ~this
.public void xor(BigRegister source)
this ^= source
.java.lang.IllegalArgumentException
- If the argument is of
different size
than this
.public void shiftLeft(int n)
this BigRegister
's contents
by a given number of bit positions. If the number is negative, a
right shift is executed.n
- Number of bit positions to shift by. If this value
is negative then a shift in the opposite direction is
executed.public void shiftRight(int n)
this BigRegister
's contents
by a given number of bit positions. If the number is negative, a
left shift is executed.n
- Number of bit positions to shift by. If this value
is negative then a shift in the opposite direction is
executed.public void rotateLeft(int n)
size
of this
register.
Effectively compute this = this << n | this >> (size - n)
.
If the number of positions to rotate by is negative, then a right instead of left rotation is executed.
public void rotateRight(int n)
size
of this
register.
Effectively compute this = this >> n | this << (size - n)
.
If the number of positions to rotate by is negative, then a left instead of right rotation is executed.
public void invertOrder()
this
.public boolean testBit(int n)
n
- Index of the bit to test.public boolean isSameValue(BigRegister x)
size
and bits
) are equal to this one;
false otherwise.
NOTE: the equals
method is not used, because this is
a mutable object (see the requirements for equals in the Java Language
Spec).
x
- BigRegister to test for equality.size
and contents.public int compareTo(BigRegister x)
this BigRegister
's contents to that of the
argument, returning -1, 0 or 1 for less than, equal to, or greater
than comparison result.x
- A BigRegister
object to compare to.this
object are
respectively less than, equal to, or greater than those
of the argument.public void setBit(int n)
n
- The bit position to alter.java.lang.IllegalArgumentException
- If the argument would
cause an ArrayOutOfBOundsException
while
accessing the bits array.public void setBits(int n, int count, long value)
count
bits starting at offset n
to a given value
.n
- The index of the first bit to set.count
- Number of bits to set.value
- New bits value, right justified in a long
.java.lang.IllegalArgumentException
- If any of the arguments would
cause an ArrayOutOfBOundsException
while
accessing the bits array, or count
is < 1 or
> 64.public void clearBit(int n)
n
- The bit position to alter.java.lang.IllegalArgumentException
- If the argument would
cause an ArrayOutOfBOundsException
while
accessing the bits array.public void flipBit(int n)
n
- The bit position to alter.java.lang.IllegalArgumentException
- If the argument would
cause an ArrayOutOfBOundsException
while
accessing the bits array.public int getBit(int n)
n
- The index of the bit to retrieve.java.lang.IllegalArgumentException
- If the argument would
cause an ArrayOutOfBOundsException
while
accessing the bits array.public long getBits(int n, int count)
count
bits starting at offset n
framed in a long
, right justified and left padded
with binary zeroes.n
- The index of the first bit to retrieve.count
- Number of bits to retrieve.count
bits starting from bit
index n
in a java long
.java.lang.IllegalArgumentException
- If any of the arguments
would cause an ArrayOutOfBOundsException
while
accessing the bits array, or count
is < 1 or
> 64.public int byteValue()
this BigRegister
.this
.public int intValue()
this BigRegister
as an int
.this
as an
int
.public long longValue()
this BigRegister
as a long
.this
as a
long
.public BigRegister valueOf(long n)
BigRegister
, of the same size
as this
set to the specified value.BigRegister
, of the same size
as this
set to the specified value.public void reset()
this BigRegister
's bits.public void atRandom()
this BigRegister
object with random data
generated from the default source.public void atRandom(java.security.SecureRandom source)
this BigRegister
object with random data
generated from a designated source.public void load(BigRegister source)
this
.java.lang.IllegalArgumentException
- If the argument is of
different size
than this
.public void load(byte[] source)
this
.
Byte array order is assumed to have its Least Significant Byte
(LSB) at index position 0. This format mirrors that of the output
returned by the toByteArray()
method.
Bits unprovided for in the source
array are cleared.
It is a more tolerant way of initialising a register than that
obtained by invoking the same method with a BigRegister
argument.
source
- The source bits organised in a byte array with
their LSB at index 0.java.lang.IllegalArgumentException
- If the argument is of
greater size
than this
.toByteArray()
public byte[] toByteArray()
this BigRegister
's contents in a
byte array with the LSB at index position 0. This format is
compatible with the load([B)
method of this class.this
in a byte array with the
LSB at index position 0.public int getSize()
size
of this
object as
specified at its instantiation time.size
of this
object
as specified at its instantiation time.public int countSetBits()
this
.this
.public int highestSetBit()
this
.this
, or
-1 if all bits are zeroes.public int lowestSetBit()
this
.this
, or
-1 if all bits are zeroes.public java.lang.String toString()
String
representation of the binary
contents of this
.toString
in class java.lang.Object
this
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |