nl.tudelft.simulation.language.util
Class BitUtil

java.lang.Object
  extended by nl.tudelft.simulation.language.util.BitUtil
All Implemented Interfaces:
Serializable

public final class BitUtil
extends Object
implements Serializable

Utilities for the bitset class.

(c) copyright 2002-2005 Delft University of Technology , the Netherlands.

See for project information www.simulation.tudelft.nl/language
License of use: Lesser General Public License (LGPL) , no warranty

Since:
1.4
Version:
$Revision: 1.1 $ $Date: 2007/01/06 13:25:55 $
Author:
Peter Jacobs
See Also:
Serialized Form

Method Summary
static BitSet fromBoolean(boolean value)
          returns a one-size BitSet with value
static BitSet fromByteArray(byte[] bytes)
           
static BitSet fromInt(int value, int length)
          returns the bitset of an integer value
static BitSet fromInteger(Integer value, int length)
          returns the bitset of an integer value
static BitSet fromString(String value)
          constructs a new BitSet from a string in the "110110" format.
static byte[] toByteArray(BitSet bits)
           
static int toInt(BitSet bits, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toByteArray

public static byte[] toByteArray(BitSet bits)
Parameters:
bits - the bitset to convert
Returns:
Returns a byte array of at least length 1. The most significant bit in the result is guaranteed not to be a 1 (since BitSet does not support sign extension). The byte-ordering of the result is big-endian which means the most significant bit is in element 0. The bit at index 0 of the bit set is assumed to be the least significant bit.

toInt

public static int toInt(BitSet bits,
                        int length)
Parameters:
bits - the bitset to convert
length - the length of the set
Returns:
Returns an int. The most significant bit in the result is guaranteed not to be a 1 (since BitSet does not support sign extension). The int-ordering of the result is big-endian which means the most significant bit is in element 0. The bit at index 0 of the bit set is assumed to be the least significant bit.

fromString

public static BitSet fromString(String value)
constructs a new BitSet from a string in the "110110" format.

Parameters:
value - the value
Returns:
the BitSet

fromByteArray

public static BitSet fromByteArray(byte[] bytes)
Parameters:
bytes - the byteArray
Returns:
Returns a bitset containing the values in bytes.The byte-ordering of bytes must be big-endian which means the most significant bit is in element 0.

fromInt

public static BitSet fromInt(int value,
                             int length)
returns the bitset of an integer value

Parameters:
value - the value
length - the length of the bitSet to produce
Returns:
the BitSet

fromInteger

public static BitSet fromInteger(Integer value,
                                 int length)
returns the bitset of an integer value

Parameters:
value - the value
length - the length of
Returns:
the BitSet

fromBoolean

public static BitSet fromBoolean(boolean value)
returns a one-size BitSet with value

Parameters:
value - the value of the bitSet
Returns:
the BitSet


Copyright © 2002-2011 Delft University of Technology, the Netherlands. All Rights Reserved.