org.wegra.util.bitset
Class BitSetManipulator

java.lang.Object
  extended byorg.wegra.util.bitset.BitSetManipulator

public final class BitSetManipulator
extends java.lang.Object

BitSet manipulator.

Author:
wegra (Bok-Youn, Lee)

Constructor Summary
BitSetManipulator()
           
 
Method Summary
static BitSet add(BitSet opr1, BitSet opr2)
          Performs a ADD operation given two bitset and return result.
static BitSet and(BitSet opr1, BitSet opr2)
          Performs a logical AND of given two bitset.
static int compare(BitSet opr1, BitSet opr2)
          Compares given two arguments for order.
static BitSet concat(BitSet[] src)
          Concatenates given BitSets
static BitSet div(BitSet opr1, BitSet opr2)
          Performs division operation to opr1 by opr2, and returns result.
static BitSet extendSign(BitSet source, int outputLength)
          extends the sign bit of source and create new BitSet of outputLength.
static BitSet mul(BitSet opr1, BitSet opr2)
          Multiply given two bit set and returns result.
static BitSet or(BitSet opr1, BitSet opr2)
          Performs a logical OR of given two bitset.
static BitSet reverse(BitSet set)
          Reverses bit pattern of given set.
static BitSet shiftLeft(BitSet opr, int length)
          Performs logical left shift.
static BitSet shiftRight(BitSet opr, int length)
          Performs logical right shift.
static BitSet shiftRightArithmetic(BitSet opr, int length)
          Performs arithmetic right shift.
static BitSet sub(BitSet opr1, BitSet opr2)
          Substracts opr2 from opr1, and return result.
static BitSet toBitSet(boolean[] bits)
          Create new BitSet from given boolean array.
static BitSet toBitSet(byte[] bytes)
          Create new BitSet from given byte array.
static BitSet toBitSet(int value)
          Create new 32bits BitSet from given integer.
static BitSet toBitSet(int value, int length)
          Create new BitSet from given integer.
static BitSet toBitSet(long value)
          Create new BitSet from given long integer.
static BitSet toBitSet(java.lang.String bitsString)
          Create new BitSet from given bits string.
static boolean[] toBooleanArray(BitSet source)
          Converts given BitSet source to boolean array.
static byte[] toByteArray(BitSet source)
          Converts given BitSet source to byte array.
static int toInteger(BitSet source)
          Converts given BitSet source to int value.
static long toLong(BitSet source)
          Converts given BitSet source to long value.
static BitSet xor(BitSet opr1, BitSet opr2)
          Performs a logical XOR of given two bitset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitSetManipulator

public BitSetManipulator()
Method Detail

and

public static BitSet and(BitSet opr1,
                         BitSet opr2)
Performs a logical AND of given two bitset. Two given bit set must have same length.


or

public static BitSet or(BitSet opr1,
                        BitSet opr2)
Performs a logical OR of given two bitset. Two given bit set must have same length.


xor

public static BitSet xor(BitSet opr1,
                         BitSet opr2)
Performs a logical XOR of given two bitset. Two given bit set must have same length.


add

public static BitSet add(BitSet opr1,
                         BitSet opr2)
Performs a ADD operation given two bitset and return result. Two given bit set must have same length.
[WARNNIG] this method does not check overflow.


sub

public static BitSet sub(BitSet opr1,
                         BitSet opr2)
Substracts opr2 from opr1, and return result.
Two given bit set must have same length.
[WARNNING] It doesn't check underflow. do yourself.


mul

public static BitSet mul(BitSet opr1,
                         BitSet opr2)
Multiply given two bit set and returns result.
Two given bit set must have same length.
[WARNNING] It doesn't check overflow. do yourself.


div

public static BitSet div(BitSet opr1,
                         BitSet opr2)
Performs division operation to opr1 by opr2, and returns result.
Two given bit set must have same length.


shiftLeft

public static BitSet shiftLeft(BitSet opr,
                               int length)
Performs logical left shift.

Parameters:
opr - the operand.
length - length to shift.
Returns:
the result of 'shift' operation.

shiftRight

public static BitSet shiftRight(BitSet opr,
                                int length)
Performs logical right shift.

Parameters:
opr - the operand.
length - length to shift.
Returns:
the result of 'shift' operation.

shiftRightArithmetic

public static BitSet shiftRightArithmetic(BitSet opr,
                                          int length)
Performs arithmetic right shift.

Parameters:
opr - the operand.
length - length to shift.
Returns:
the result of 'shift' operation.

compare

public static int compare(BitSet opr1,
                          BitSet opr2)
Compares given two arguments for order.

Parameters:
opr1 - the first object to be compared.
opr2 - the second object to be compared.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

extendSign

public static BitSet extendSign(BitSet source,
                                int outputLength)
extends the sign bit of source and create new BitSet of outputLength.

Parameters:
source - source BitSet
outputLength - length of output BitSet
Returns:
sign extended BitSet

concat

public static BitSet concat(BitSet[] src)
Concatenates given BitSets


reverse

public static BitSet reverse(BitSet set)
Reverses bit pattern of given set.

Returns:
Reversed BitSet.

toBitSet

public static BitSet toBitSet(byte[] bytes)
Create new BitSet from given byte array.


toBitSet

public static BitSet toBitSet(boolean[] bits)
Create new BitSet from given boolean array.


toBitSet

public static BitSet toBitSet(int value)
Create new 32bits BitSet from given integer. Given integer value mean the value of BitSet's bits, not the length.


toBitSet

public static BitSet toBitSet(int value,
                              int length)
Create new BitSet from given integer. Given integer value means the value of BitSet's bits, not the length.


toBitSet

public static BitSet toBitSet(long value)
Create new BitSet from given long integer. Given long integer value means the value of BitSet's bits, not the length.


toBitSet

public static BitSet toBitSet(java.lang.String bitsString)
Create new BitSet from given bits string.


toBooleanArray

public static boolean[] toBooleanArray(BitSet source)
Converts given BitSet source to boolean array.

Parameters:
source - the source to convert
Returns:
a converted boolean array from the source

toByteArray

public static byte[] toByteArray(BitSet source)
Converts given BitSet source to byte array.

Parameters:
source - the source to convert
Returns:
a converted byte array from the source

toInteger

public static int toInteger(BitSet source)
Converts given BitSet source to int value.

Parameters:
source - the source to convert
Returns:
a converted int value from the source

toLong

public static long toLong(BitSet source)
Converts given BitSet source to long value.

Parameters:
source - the source to convert
Returns:
a converted long value from the source