Evolvica Core API Version 0.6.2
Last Modified: June 29 2004

org.evolvica.util
Class BitVector

java.lang.Object
  extended byorg.evolvica.util.BitVector
All Implemented Interfaces:
java.lang.Cloneable

public class BitVector
extends java.lang.Object
implements java.lang.Cloneable

Replacement for Sun's unflexible BitSet.

Since:
0.1
Version:
$Revision: 1.4 $ $Date: 2004/05/26 11:58:35 $
Author:
Andreas Rummler

Constructor Summary
BitVector()
          Constructor.
BitVector(BitVector bv)
          Copy Constructor.
BitVector(int length)
          Constructor.
BitVector(java.lang.String pattern)
          Constructs a bit vector from a given string pattern.
 
Method Summary
 BitVector and(BitVector bv)
          Performs an AND conjunction.
 void clear(int index)
          Clears the bit at the given index.
 java.lang.Object clone()
           
 boolean get(int index)
          Returns the bit at the given position.
 int getAsInteger(int index)
          Returns the value of the bit at the given position as an integer.
 void invert()
          Inverts the whole vector.
 int length()
          Returns the length of the bit vector.
 BitVector or(BitVector bv)
          Performs an OR function.
 void randomize()
          Randomizes the bitstring.
 void set(int index)
          Sets the bit at the given index to true.
 void set(int index, boolean value)
          Sets the bit at the given index to the given value.
 void shiftLeft()
          Performs a shift left.
 void shiftLeft(int amount)
          Performs a shift left by the specified amount.
 void shiftRight()
          Performs a shift right.
 void shiftRight(int amount)
          Performs a shift right by the specified amount.
 java.lang.String toBlockString()
          Returns the bit vector as blocks of 8 bits.
 java.lang.String toBlockString(int blockLength)
          Returns the bit vector as blocks of the given block length.
 void toggle(int index)
          Toggles the bit at the given index.
 java.lang.String toString()
          Returns a string representation of the bit vector.
 BitVector xor(BitVector bv)
          Performs a XOR function.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitVector

public BitVector()
Constructor. Constructs a bitvector of length 1.


BitVector

public BitVector(int length)
Constructor. Constructs a bitvector of the given length.

Parameters:
length - length of the bit vector, must be greater than 0

BitVector

public BitVector(BitVector bv)
Copy Constructor.

Parameters:
bv - bit vector to be copied

BitVector

public BitVector(java.lang.String pattern)
Constructs a bit vector from a given string pattern. MSB comes first.

Parameters:
pattern - string pattern
Method Detail

and

public BitVector and(BitVector bv)
Performs an AND conjunction.

Parameters:
bv - second bit vector
Returns:
result of the AND conjunction

clear

public void clear(int index)
Clears the bit at the given index.

Parameters:
index - index of the bit

clone

public java.lang.Object clone()
See Also:
Object.clone()

get

public boolean get(int index)
Returns the bit at the given position.

Parameters:
index - index of the bit
Returns:
value of the bit at the given position

getAsInteger

public int getAsInteger(int index)
Returns the value of the bit at the given position as an integer.

Parameters:
index - index of the bit
Returns:
value of the bit as an integer

invert

public void invert()
Inverts the whole vector.


length

public int length()
Returns the length of the bit vector.

Returns:
length of the bitstring

or

public BitVector or(BitVector bv)
Performs an OR function.

Parameters:
bv - second bit vector
Returns:
result of the OR function

randomize

public void randomize()
Randomizes the bitstring.


set

public void set(int index)
Sets the bit at the given index to true.

Parameters:
index - index of the bit

set

public void set(int index,
                boolean value)
Sets the bit at the given index to the given value.

Parameters:
index - index of the bit
value - value to set

shiftLeft

public void shiftLeft()
Performs a shift left.


shiftLeft

public void shiftLeft(int amount)
Performs a shift left by the specified amount.

Parameters:
amount - amount to shift

shiftRight

public void shiftRight()
Performs a shift right.


shiftRight

public void shiftRight(int amount)
Performs a shift right by the specified amount.

Parameters:
amount - amount to shift

toBlockString

public java.lang.String toBlockString()
Returns the bit vector as blocks of 8 bits. The MSB comes first in each block, the most significant blocks comes also first.

Returns:
string representation

toBlockString

public java.lang.String toBlockString(int blockLength)
Returns the bit vector as blocks of the given block length. The MSB comes first in each block, the most significant blocks comes also first.

Parameters:
blockLength - block length
Returns:
string representation

toggle

public void toggle(int index)
Toggles the bit at the given index.

Parameters:
index - position of the bit in bit vector

toString

public java.lang.String toString()
Returns a string representation of the bit vector. This method simply prints all bits from length to 0 sequentially. MSB comes first.

Returns:
string representation

xor

public BitVector xor(BitVector bv)
Performs a XOR function.

Parameters:
bv - second bit vector
Returns:
result of the XOR function

Evolvica Core API Version 0.6.2
Last Modified: June 29 2004

Copyright © 2000-2004 Technical University of Ilmenau, Department Electronic Circuits and Systems