Class BitUtil
java.lang.Object
nl.tudelft.simulation.language.util.BitUtil
Utilities for the BitSet class.
Copyright (c) 2009-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information DSOL Manual. The DSOL project is distributed under a three-clause BSD-style license, which can be found at DSOL License.
- Author:
- Peter Jacobs , Alexander Verbraeck
-
Method Summary
Modifier and TypeMethodDescriptionstatic BitSetfromBoolean(boolean value) returns a one-size BitSet with value.static BitSetfromByteArray(byte[] bytes) static BitSetfromInt(int value, int length) returns the bitset of an integer value.static BitSetfromInteger(Integer value, int length) returns the bitset of an integer value.static BitSetfromString(String value) constructs a new BitSet from a string in the "110110" format, or the {0, 1, 3, 5, 8, 12} format.static byte[]toByteArray(BitSet bits) static int
-
Method Details
-
toByteArray
- 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.
-
fromInt
returns the bitset of an integer value.- Parameters:
value- the valuelength- the length of the bitSet to produce- Returns:
- the BitSet
-
fromInteger
returns the bitset of an integer value.- Parameters:
value- the valuelength- the length of- Returns:
- the BitSet
-
toInt
- Parameters:
bits- the bitset to convertlength- 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
constructs a new BitSet from a string in the "110110" format, or the {0, 1, 3, 5, 8, 12} format. Note that for the binary representation, the LEAST SIGNIFICANT BIT COMES FIRST. So, 001 represents the value 4 and not 1.- Parameters:
value- the value- Returns:
- the BitSet
-
fromByteArray
- 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.
-
fromBoolean
returns a one-size BitSet with value.- Parameters:
value- the value of the bitSet- Returns:
- the BitSet
-