sdsu.util
Class ConvertableBitSet

java.lang.Object
  |
  +--sdsu.util.ConvertableBitSet

public final class ConvertableBitSet
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class extends the functionality of java.util.BitSet. Since java.util.BitSet is a final class, ConvertableBitSet is not a subclass of java.util.BitSet. It adds the ablity to convert between basic types (ints, float) and BitSet objects.

Version:
1.0 5 January 1999
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
Serialized Form

Constructor Summary
ConvertableBitSet()
           
ConvertableBitSet(int size)
          Contructs a BitSet object with given number of bits, all set to zero.
 
Method Summary
 void and(java.util.BitSet set)
          Logically ANDs current ConvertableBitSet with the specified BitSet.
 void and(ConvertableBitSet set)
          Logically ANDs current ConvertableBitSet with the specified ConvertableBitSet.
 void clear(int bit)
          Sets the given bit to zero (or false).
 java.lang.Object clone()
           
 boolean equals(java.lang.Object anObject)
           
static ConvertableBitSet fromDouble(double value)
          Returns the bitset representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.
static ConvertableBitSet fromFloat(float value)
          Returns the bitset represention of a single-float value.
static ConvertableBitSet fromInt(int value)
           
static ConvertableBitSet fromLong(long value)
           
static ConvertableBitSet fromString(java.lang.String bits)
           
 boolean get(int bit)
          Returns the value of the given bit.
 int hashCode()
           
 void or(java.util.BitSet set)
          Logically ORs current ConvertableBitSet with the specified BitSet.
 void or(ConvertableBitSet set)
          Logically ORs current ConvertableBitSet with the specified ConvertableBitSet.
 void set(int bit)
          Sets the given bit to one (or true).
 int size()
          Returns the number of bits in the ConvertableBitSet.
 double toDouble()
          Constucts a double from the bitset.
 java.lang.String toDoubleString()
          Return a string representation of the ConvertableBitSet as if it represented a double.
 float toFloat()
          Constucts a float from the bitset.
 java.lang.String toFloatString()
          Return a string representation of the ConvertableBitSet as if it represented a float.
 int toInt()
          Constucts an int from the bitset.
 int toLong()
          Constucts an int from the bitset.
 java.lang.String toString()
          Returns a string representation of the bitset.
 java.lang.String toString(int numberOfBits)
          Returns a String representation of the bitset using the first numberOfBits of the bitset.
 void xor(java.util.BitSet set)
          Logically XORs current ConvertableBitSet with the specified BitSet.
 void xor(ConvertableBitSet set)
          Logically XORs current ConvertableBitSet with the specified ConvertableBitSet.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConvertableBitSet

public ConvertableBitSet()

ConvertableBitSet

public ConvertableBitSet(int size)
Contructs a BitSet object with given number of bits, all set to zero.
Method Detail

fromString

public static ConvertableBitSet fromString(java.lang.String bits)
Parameters:
bits - a string representation of the bits. All characters in the string must be '0' or '1'. The low order bit is on the right end of the string

fromInt

public static ConvertableBitSet fromInt(int value)
Returns:
A bitset that represents the bit pattern of the int "value" The low order bit in the int is bit zero in the bitset.

fromLong

public static ConvertableBitSet fromLong(long value)
Returns:
A bitset that represents the bit pattern of the long "value". The low order bit in the long is bit zero in the bitset.

fromFloat

public static ConvertableBitSet fromFloat(float value)
Returns the bitset represention of a single-float value. The result is a representation of the floating-point argument according to the IEEE 754 floating-point "single precision" bit layout.

Bit 31 represents the sign of the floating-point number. Bits 30-23 represent the exponent. Bits 22-0 represent the mantissa (or significand) of the floating-point number.

If the argument is positive infinity, the result is 0x7f800000.
If the argument is negative infinity, the result is 0xff800000.
If the argument is NaN, the result is 0x7fc00000.

Returns:
A bitset that represents the bit pattern of the float "value".

fromDouble

public static ConvertableBitSet fromDouble(double value)
Returns the bitset representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.

Bit 63 represents the sign of the floating-point number. Bits 62-52 represent the exponent. Bits 51-0 represent the mantissa or significand of the floating-point number.

If the argument is positive infinity, the result is 0x7ff0000000000000L.
If the argument is negative infinity, the result is 0xfff0000000000000L.
If the argument is NaN, the result is 0x7ff8000000000000L.


toFloat

public float toFloat()
Constucts a float from the bitset. Uses the IEEE 754 floating-point "single precision" bit layout to construct the float. Only the first 32 bits in the BitSet are used.

toDouble

public double toDouble()
Constucts a double from the bitset. Uses the IEEE 754 floating-point "double format" bit layout to construct the float. Only the first 64 bits in the BitSet are used.

toInt

public int toInt()
Constucts an int from the bitset. Only the first 32 bits in the BitSet are used.

toLong

public int toLong()
Constucts an int from the bitset. Only the first 64 bits in the BitSet are used.

and

public void and(ConvertableBitSet set)
Logically ANDs current ConvertableBitSet with the specified ConvertableBitSet.

and

public void and(java.util.BitSet set)
Logically ANDs current ConvertableBitSet with the specified BitSet.

or

public void or(java.util.BitSet set)
Logically ORs current ConvertableBitSet with the specified BitSet.

or

public void or(ConvertableBitSet set)
Logically ORs current ConvertableBitSet with the specified ConvertableBitSet.

xor

public void xor(java.util.BitSet set)
Logically XORs current ConvertableBitSet with the specified BitSet.

xor

public void xor(ConvertableBitSet set)
Logically XORs current ConvertableBitSet with the specified ConvertableBitSet.

clear

public void clear(int bit)
Sets the given bit to zero (or false).

get

public boolean get(int bit)
Returns the value of the given bit.

set

public void set(int bit)
Sets the given bit to one (or true).

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

size

public int size()
Returns the number of bits in the ConvertableBitSet.

equals

public boolean equals(java.lang.Object anObject)
Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()

toString

public java.lang.String toString()
Returns a string representation of the bitset. Includes one bit beyond the highest order one (true) bit.
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int numberOfBits)
Returns a String representation of the bitset using the first numberOfBits of the bitset.

toFloatString

public java.lang.String toFloatString()
Return a string representation of the ConvertableBitSet as if it represented a float. A "," separates the bit that represent the sign bit (bit 31), the bits that represent the exponent (bits 30-23) and the bits that represent the mantissa (or significand) (bits 22-0).

toDoubleString

public java.lang.String toDoubleString()
Return a string representation of the ConvertableBitSet as if it represented a double. A "," separates the bit that represent the sign bit (bit 63), the bits that represent the exponent (bits 62-52) and the bits that represent the mantissa (or significand) (bits 51-0).