Java Utililty Methods Bit Set

List of utility methods to do Bit Set

Description

The list of methods to do Bit Set are organized into topic(s).

Method

voidSetBit(byte _bitset, byte bit)
Set Bit
_bitset |= bit;
bytesetBit(byte _byte, int position, boolean value)
Sets a bit in the byte
position--;
return (byte) (value ? _byte | 1 << position : _byte & ~(1 << position));
voidsetBit(byte a, int pos, boolean set)
set byte a's pos'th bit
if (true == set) {
    a = (byte) (a | (1 << pos));
} else {
    a = (byte) (a & ~(1 << pos));
bytesetBit(byte b, int i)
set Bit
return (byte) logicalOR(b, bitMask(i));
bytesetBit(byte b, int pos)
set Bit
return (byte) (b | (1 << pos));
bytesetBit(byte data, byte bit, boolean value)
set Bit
if (value) {
    data = (byte) (data | (1 << bit));
} else {
    data = (byte) (data & ~(1 << bit));
return data;
bytesetBit(byte data, int bitNumber, boolean value)
set Bit
if (bitNumber < 0 || bitNumber > 7)
    throw new IllegalArgumentException("bitNumber out of range");
return (byte) setBit(data & 0xFF, bitNumber, value);
bytesetBit(byte data, int bitPos, boolean on)
set Bit
if (bitPos < 1 || bitPos > 8) {
    throw new IllegalArgumentException("parameter 'bitPos' must be between 1 and 8. bitPos=" + bitPos);
if (on) { 
    return data |= 1 << (bitPos - 1);
} else { 
    return data &= ~(1 << (bitPos - 1));
bytesetBit(byte data, int pos, int val)
Set one bit in a byte at the specified position with the specified bit value.
int posBit = pos % 8;
return (byte) ((val << (8 - (posBit + 1))) | data);
bytesetBit(byte in, int position, boolean value)
set Bit
if (!value) {
    return (byte) (in & (0xFF ^ 1 << 8 - position));
} else {
    return setBit(in, position);