All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class cryptix.util.math.BigRegister

java.lang.Object
   |
   +----cryptix.util.math.BigRegister

public synchronized class BigRegister
extends Object
implements Cloneable, Serializable
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.1.1.1 $

Author:
Raif S. Naffah

Variable Index

 o MAXIMUM_SIZE
Maximum allowed number of bits in a BigRegister object.

Constructor Index

 o BigRegister(int)
Instantiate a BigRegister of a given size with all its bits set to zeroes.

Method Index

 o and(BigRegister)
Compute this &= source.
 o andNot(BigRegister)
Compute this &= ~source.
 o atRandom()
Fill this BigRegister object with random data generated from the default source.
 o atRandom(SecureRandom)
Fill this BigRegister object with random data generated from a designated source.
 o byteValue()
Return the rightmost byte value in this BigRegister.
 o clearBit(int)
Set the bit at the designated position to 0; ie.
 o clone()
Return a reference to a duplicate of this.
 o compareTo(BigRegister)
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.
 o countSetBits()
Return the number of bits set (to 1) in this.
 o flipBit(int)
Flip the value of the bit at the designated position.
 o getBit(int)
Return 1 or 0 if the designated bit was set or cleared respectively.
 o getBits(int, int)
Return count bits starting at offset n framed in a long, right justified and left padded with binary zeroes.
 o getSize()
Return the size of this object as specified at its instantiation time.
 o highestSetBit()
Return the index of the leftmost non-zero bit in this.
 o intValue()
Return the rightmost 32-bit value in this BigRegister as an int.
 o invertOrder()
Invert the bit order of the current contents of this.
 o isSameValue(BigRegister)
Return true if the parameters of the BigRegister x (size and bits) are equal to this one; false otherwise.
 o load(BigRegister)
Copy the argument's value into this.
 o load(byte[])
Copy the bit values from a byte array into this.
 o longValue()
Return the rightmost 64-bit value in this BigRegister as a long.
 o lowestSetBit()
Return the index of the rightmost non-zero bit in this.
 o not()
Compute this = ~this.
 o or(BigRegister)
Compute this |= source.
 o reset()
Reset to zeroes all this BigRegister's bits.
 o rotateLeft(int)
Circular left shift over the size of this register.
 o rotateRight(int)
Circular right shift over the size of this register.
 o setBit(int)
Set the bit at the designated position to 1.
 o setBits(int, int, long)
Set count bits starting at offset n to a given value.
 o shiftLeft(int)
Execute a left shift of this BigRegister's contents by a given number of bit positions.
 o shiftRight(int)
Execute a right shift of this BigRegister's contents by a given number of bit positions.
 o testBit(int)
Return true if the designated bit is set or false otherwise.
 o toByteArray()
Return a copy of this BigRegister's contents in a byte array with the LSB at index position 0.
 o toString()
Return a formatted String representation of the binary contents of this.
 o valueOf(long)
Return a BigRegister, of the same size as this set to the specified value.
 o xor(BigRegister)
Compute this ^= source.

Variables

 o MAXIMUM_SIZE
 public static final int MAXIMUM_SIZE
Maximum allowed number of bits in a BigRegister object.

Constructors

 o BigRegister
 public BigRegister(int size)
Instantiate a BigRegister of a given size with all its bits set to zeroes.

Parameters:
size - Number of meaningful bits in this object.
Throws: IllegalArgumentException
If the argument is less than 2 or greater than the maximum allowed value.
See Also:
MAXIMUM_SIZE

Methods

 o clone
 public Object clone()
Return a reference to a duplicate of this.

Overrides:
clone in class Object
 o and
 public void and(BigRegister source)
Compute this &= source.

Throws: IllegalArgumentException
If the argument is of different size than this.
 o andNot
 public void andNot(BigRegister source)
Compute this &= ~source.

Throws: IllegalArgumentException
If the argument is of different size than this.
 o or
 public void or(BigRegister source)
Compute this |= source.

Throws: IllegalArgumentException
If the argument is of different size than this.
 o not
 public void not()
Compute this = ~this.

 o xor
 public void xor(BigRegister source)
Compute this ^= source.

Throws: IllegalArgumentException
If the argument is of different size than this.
 o shiftLeft
 public void shiftLeft(int n)
Execute a left shift of this 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.
 o shiftRight
 public void shiftRight(int n)
Execute a right shift of this 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.
 o rotateLeft
 public void rotateLeft(int n)
Circular left shift over the 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.

 o rotateRight
 public void rotateRight(int n)
Circular right shift over the 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.

 o invertOrder
 public void invertOrder()
Invert the bit order of the current contents of this.

 o testBit
 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.
 o isSameValue
 public boolean isSameValue(BigRegister x)
Return true if the parameters of the 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).

Parameters:
x - BigRegister to test for equality.
Returns:
true iff x has equal size and contents.
 o compareTo
 public 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.

Parameters:
x - A BigRegister 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.
 o setBit
 public void setBit(int n)
Set the bit at the designated position to 1.

Parameters:
n - The bit position to alter.
Throws: IllegalArgumentException
If the argument would cause an ArrayOutOfBOundsException while accessing the bits array.
 o setBits
 public void setBits(int n,
                     int count,
                     long value)
Set count bits starting at offset n to a given value.

Parameters:
n - The index of the first bit to set.
count - Number of bits to set.
value - New bits value, right justified in a long.
Throws: IllegalArgumentException
If any of the arguments would cause an ArrayOutOfBOundsException while accessing the bits array, or count is < 1 or > 64.
 o clearBit
 public void clearBit(int n)
Set the bit at the designated position to 0; ie. clear it.

Parameters:
n - The bit position to alter.
Throws: IllegalArgumentException
If the argument would cause an ArrayOutOfBOundsException while accessing the bits array.
 o flipBit
 public void flipBit(int n)
Flip the value of the bit at the designated position.

Parameters:
n - The bit position to alter.
Throws: IllegalArgumentException
If the argument would cause an ArrayOutOfBOundsException while accessing the bits array.
 o getBit
 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.
Throws: IllegalArgumentException
If the argument would cause an ArrayOutOfBOundsException while accessing the bits array.
 o getBits
 public 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.

Parameters:
n - The index of the first bit to retrieve.
count - Number of bits to retrieve.
Returns:
Right justified count bits starting from bit index n in a java long.
Throws: IllegalArgumentException
If any of the arguments would cause an ArrayOutOfBOundsException while accessing the bits array, or count is < 1 or > 64.
 o byteValue
 public int byteValue()
Return the rightmost byte value in this BigRegister.

Returns:
The rightmost byte value in this.
 o intValue
 public int intValue()
Return the rightmost 32-bit value in this BigRegister as an int.

Returns:
The rightmost 32-bit value in this as an int.
 o longValue
 public long longValue()
Return the rightmost 64-bit value in this BigRegister as a long.

Returns:
The rightmost 64-bit value in this as a long.
 o valueOf
 public BigRegister valueOf(long n)
Return a BigRegister, of the same size as this set to the specified value.

Returns:
A BigRegister, of the same size as this set to the specified value.
 o reset
 public void reset()
Reset to zeroes all this BigRegister's bits.

 o atRandom
 public void atRandom()
Fill this BigRegister object with random data generated from the default source.

 o atRandom
 public void atRandom(SecureRandom source)
Fill this BigRegister object with random data generated from a designated source.

 o load
 public void load(BigRegister source)
Copy the argument's value into this.

Throws: IllegalArgumentException
If the argument is of different size than this.
 o load
 public void load(byte source[])
Copy the bit values from a byte array into 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.

Parameters:
source - The source bits organised in a byte array with their LSB at index 0.
Throws: IllegalArgumentException
If the argument is of greater size than this.
See Also:
toByteArray
 o toByteArray
 public byte[] toByteArray()
Return a copy of 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.

Returns:
The bits of this in a byte array with the LSB at index position 0.
 o getSize
 public int getSize()
Return the size of this object as specified at its instantiation time.

Returns:
The size of this object as specified at its instantiation time.
 o countSetBits
 public int countSetBits()
Return the number of bits set (to 1) in this.

Returns:
The number of set bits in this.
 o highestSetBit
 public int highestSetBit()
Return the index of the leftmost non-zero bit in this.

Returns:
Index of the leftmost non-zero bit in this, or -1 if all bits are zeroes.
 o lowestSetBit
 public int lowestSetBit()
Return the index of the rightmost non-zero bit in this.

Returns:
Index of the rightmost non-zero bit in this, or -1 if all bits are zeroes.
 o toString
 public String toString()
Return a formatted String representation of the binary contents of this.

Returns:
A formatted string representation of the binary contents of this.
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index