Class BitUtil
java.lang.Object
nl.tudelft.simulation.language.util.BitUtil
- All Implemented Interfaces:
Serializable
Utilities for the BitSet class.
Copyright (c) 2009-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.
- Author:
- Peter Jacobs , Alexander Verbraeck
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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, or the {0, 1, 3, 5, 8, 12} format.static byte[]
toByteArray
(BitSet bits) static int
-
Method Details
-
toByteArray
- Parameters:
bits
- BitSet; 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
- int; the valuelength
- int; the length of the bitSet to produce- Returns:
- the BitSet
-
fromInteger
returns the bitset of an integer value.- Parameters:
value
- Integer; the valuelength
- int; the length of- Returns:
- the BitSet
-
toInt
- Parameters:
bits
- BitSet; the bitset to convertlength
- int; 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
- String; the value- Returns:
- the BitSet
-
fromByteArray
- Parameters:
bytes
- byte[]; 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
- boolean; the value of the bitSet- Returns:
- the BitSet
-