public final class BitManip extends Object
The value of a single bit can be easily retrieved with the getBit(byte, int) method.
Setting a bit is a little bit more complicated. The byte to be changed must be set to the return value of
getByteWithBitSet(byte, int, boolean).
| Constructor and Description |
|---|
BitManip() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
getBit(byte b,
int bitNumber)
Returns
true, if the bit at the given position is set to one and false if
it is set to zero . |
static byte |
getByteWithBitSet(byte b,
int bitNumber,
boolean value)
Sets a single bit.
|
public static final byte getByteWithBitSet(byte b,
int bitNumber,
boolean value)
true, the bit will be set to one,
and to zero otherwise. All other bits will be left unchanged.
The bits are numbered in big-endian format, from 0 (LSB) to 7 (MSB).
+---+---+---+---+---+---+---+---+
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | bit number
+---+---+---+---+---+---+---+---+
b - the original byte valuebitNumber - the big-endian position of the bit to be changed, from 0 to 7value - true for 1, false for 0public static boolean getBit(byte b,
int bitNumber)
true, if the bit at the given position is set to one and false if
it is set to zero . The bits are numbered in big-endian format, from 0 (LSB) to 7 (MSB).
+---+---+---+---+---+---+---+---+
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | bit number
+---+---+---+---+---+---+---+---+
b - the byte value in questionbitNumber - the big-endian position of the bit to be changed, from 0 to 7true if bit is set to one, else falseCopyright © 2013 University of Konstanz, Distributed Systems Group. All Rights Reserved.