nl.tudelft.simulation.language.util
Class BitUtil

java.lang.Object
  extended bynl.tudelft.simulation.language.util.BitUtil
All Implemented Interfaces:
java.io.Serializable

public final class BitUtil
extends java.lang.Object
implements java.io.Serializable

Utilities for the bitset class.

(c) copyright 2003 Delft University of Technology , the Netherlands.
See for project information www.simulation.tudelft.nl
License of use: General Public License (GPL) , no warranty

Since:
1.4
Version:
1.2 Apr 27, 2004
Author:
Peter Jacobs
See Also:
Serialized Form

Method Summary
static java.util.BitSet fromBoolean(boolean value)
          returns a one-size BitSet with value
static java.util.BitSet fromByteArray(byte[] bytes)
           
static java.util.BitSet fromInt(int value, int length)
          returns the bitset of an integer value
static java.util.BitSet fromInteger(java.lang.Integer value, int length)
          returns the bitset of an integer value
static java.util.BitSet fromString(java.lang.String value)
          constructs a new BitSet from a string in the "110110" format.
static byte[] toByteArray(java.util.BitSet bits)
           
static int toInt(java.util.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(java.util.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(java.util.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 java.util.BitSet fromString(java.lang.String value)
constructs a new BitSet from a string in the "110110" format.

Parameters:
value - the value
Returns:
the BitSet

fromByteArray

public static java.util.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 java.util.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 java.util.BitSet fromInteger(java.lang.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 java.util.BitSet fromBoolean(boolean value)
returns a one-size BitSet with value

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


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