Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
cryptix.util.math.BigRegister
public class BigRegister
extends java.lang.Object
implements Cloneable, Serializable
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.
Field Summary | |
static int |
|
Constructor Summary | |
|
Method Summary | |
void |
|
void |
|
void |
|
void |
|
int |
|
void |
|
Object |
|
int |
|
int |
|
void |
|
int |
|
long |
|
int |
|
int |
|
int |
|
void |
|
boolean |
|
void |
|
void |
|
long |
|
int |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
boolean |
|
byte[] |
|
String |
|
BigRegister |
|
void |
|
public static final int MAXIMUM_SIZE
Maximum allowed number of bits in aBigRegister
object.
- Field Value:
- 4096
public BigRegister(int size)
Instantiate aBigRegister
of a givensize
with all its bits set to zeroes.
- Parameters:
size
- Number of meaningful bits inthis
object.
- See Also:
MAXIMUM_SIZE
public void atRandom()
Fillthis BigRegister
object with random data generated from the default source.
public void atRandom(SecureRandom source)
Fillthis BigRegister
object with random data generated from a designated source.
public int byteValue()
Return the rightmost byte value inthis BigRegister
.
- Returns:
- The rightmost byte value in
this
.
public void clearBit(int n)
Set the bit at the designated position to 0; ie. clear it.
- Parameters:
n
- The bit position to alter.
public Object clone()
Return a reference to a duplicate ofthis
.
public int compareTo(BigRegister x)
Comparethis BigRegister
's contents to that of the argument, returning -1, 0 or 1 for less than, equal to, or greater than comparison result.
- Parameters:
x
- ABigRegister
object to compare to.
- Returns:
- -1, 0, +1 If the contents of
this
object are respectively less than, equal to, or greater than those of the argument.
public int countSetBits()
Return the number of bits set (to 1) inthis
.
- Returns:
- The number of set bits in
this
.
public void flipBit(int n)
Flip the value of the bit at the designated position.
- Parameters:
n
- The bit position to alter.
public int getBit(int n)
Return 1 or 0 if the designated bit was set or cleared respectively.
- Parameters:
n
- The index of the bit to retrieve.
public long getBits(int n, int count)
Returncount
bits starting at offsetn
framed in along
, right justified and left padded with binary zeroes.
- Parameters:
n
- The index of the first bit to retrieve.count
- Number of bits to retrieve.
- Returns:
- Right justified
count
bits starting from bit indexn
in a javalong
.
public int getSize()
Return thesize
ofthis
object as specified at its instantiation time.
- Returns:
- The
size
ofthis
object as specified at its instantiation time.
public int highestSetBit()
Return the index of the leftmost non-zero bit inthis
.
- Returns:
- Index of the leftmost non-zero bit in
this
, or -1 if all bits are zeroes.
public int intValue()
Return the rightmost 32-bit value inthis BigRegister
as anint
.
- Returns:
- The rightmost 32-bit value in
this
as anint
.
public void invertOrder()
Invert the bit order of the current contents ofthis
.
public boolean isSameValue(BigRegister x)
Return true if the parameters of the BigRegister x (size
andbits
) are equal to this one; false otherwise. NOTE: theequals
method is not used, because this is a mutable object (see the requirements for equals in the Java Language Spec).
- Parameters:
x
- BigRegister to test for equality.
- Returns:
- true iff x has equal
size
and contents.
public void load(byte[] source)
Copy the bit values from a byte array intothis
. 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 thetoByteArray()
method. Bits unprovided for in thesource
array are cleared. It is a more tolerant way of initialising a register than that obtained by invoking the same method with aBigRegister
argument.
- Parameters:
source
- The source bits organised in a byte array with their LSB at index 0.
- See Also:
toByteArray()
public long longValue()
Return the rightmost 64-bit value inthis BigRegister
as along
.
- Returns:
- The rightmost 64-bit value in
this
as along
.
public int lowestSetBit()
Return the index of the rightmost non-zero bit inthis
.
- Returns:
- Index of the rightmost non-zero bit in
this
, or -1 if all bits are zeroes.
public void not()
Computethis = ~this
.
public void reset()
Reset to zeroes allthis BigRegister
's bits.
public void rotateLeft(int n)
Circular left shift over thesize
ofthis
register. Effectively computethis = 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)
Circular right shift over thesize
ofthis
register. Effectively computethis = 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 setBit(int n)
Set the bit at the designated position to 1.
- Parameters:
n
- The bit position to alter.
public void setBits(int n, int count, long value)
Setcount
bits starting at offsetn
to a givenvalue
.
- Parameters:
n
- The index of the first bit to set.count
- Number of bits to set.value
- New bits value, right justified in along
.
public void shiftLeft(int n)
Execute a left shift ofthis BigRegister
's contents by a given number of bit positions. If the number is negative, a right shift is executed.
- Parameters:
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)
Execute a right shift ofthis BigRegister
's contents by a given number of bit positions. If the number is negative, a left shift is executed.
- Parameters:
n
- Number of bit positions to shift by. If this value is negative then a shift in the opposite direction is executed.
public boolean testBit(int n)
Return true if the designated bit is set or false otherwise.
- Parameters:
n
- Index of the bit to test.
- Returns:
- true if the designated bit is set or false otherwise.
public byte[] toByteArray()
Return a copy ofthis BigRegister
's contents in a byte array with the LSB at index position 0. This format is compatible with theload([B)
method of this class.
- Returns:
- The bits of
this
in a byte array with the LSB at index position 0.
public String toString()
Return a formattedString
representation of the binary contents ofthis
.
- Returns:
- A formatted string representation of the binary contents of
this
.
public BigRegister valueOf(long n)
Return aBigRegister
, of the samesize
asthis
set to the specified value.
- Returns:
- A
BigRegister
, of the samesize
asthis
set to the specified value.