public class Bits extends Object
| Constructor and Description |
|---|
Bits() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
decodeBit(int value,
int bitIndex)
Decodes a single bit from the given value.
|
static int |
decodeBits(int value,
int bitIndex,
int numberOfBits)
Decodes
numberOfBits bits from the specified start index. |
static int |
encodeBits(int oldValue,
int bitIndex,
int numberOfBits,
int newValue)
Changes
numberOfBits bits starting from index
bitIndex in octet to the
numberOfBits lowest bits from newValue. |
static int |
rotateLeft(int value,
int distance)
Rotates the bits in the given value to the left.
|
static long |
rotateLeft(long value,
int distance)
Rotates the bits in the given value to the left.
|
static int |
rotateRight(int value,
int distance)
Rotates the bits in the given value to the right.
|
static long |
rotateRight(long value,
int distance)
Rotates the bits in the given value to the right.
|
public static boolean decodeBit(int value,
int bitIndex)
value - The value to decode the bit frombitIndex - The number of the bit (0 being the LSB, 31 the MSB)public static int decodeBits(int value,
int bitIndex,
int numberOfBits)
numberOfBits bits from the specified start index.
The resulting value has the range 0 to
2 ^ numberOfBits - 1.value - The value to decode bits frombitIndex - The index of the first bit to decodenumberOfBits - The number of bits to decodepublic static int encodeBits(int oldValue,
int bitIndex,
int numberOfBits,
int newValue)
numberOfBits bits starting from index
bitIndex in octet to the
numberOfBits lowest bits from newValue.oldValue - The value to changebitIndex - The index of the lowest bit to changenumberOfBits - The number of bits to changenewValue - The new value of the changed bitsoctet with the specified bits changedpublic static int rotateLeft(int value,
int distance)
value - The value to rotatedistance - The distance of the rotation, in bitspublic static long rotateLeft(long value,
int distance)
value - The value to rotatedistance - The distance of the rotation, in bitspublic static int rotateRight(int value,
int distance)
value - The value to rotatedistance - The distance of the rotation, in bitspublic static long rotateRight(long value,
int distance)
value - The value to rotatedistance - The distance of the rotation, in bitsCopyright © 2026. All rights reserved.