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

intsetBit(int f, int i)
set and unset a bit in an integer
int k = (1 << i);
if (f % (2 * k) < k) {
    return f + k;
return f;
intsetBit(int flag, int i)
set Bit
return flag | pow2(i);
intsetBit(int flags, int bit)
Set a bit or bit combination on bitmap
return flags | bit;
intsetBit(int i, int bit, boolean enabled)
Sets/unsets a bit in the given integer.
if (enabled)
    i |= bit;
else
    i &= ~bit;
return i;
intsetBit(int i, int bit, boolean state)
set Bit
int mask = 1 << bit;
if (state) {
    i |= mask;
} else {
    i &= ~mask;
return i;
intsetBit(int integer, int bit)
set Bit
return (integer | (1 << bit));
intsetBit(int mask, int bit, boolean value)
set Bit
mask |= (value ? 1 : 0) << bit;
return mask;
intsetBit(int n, int bitPosition)
Sets bit position in a copy of the integer and returns it
int number = n;
int bitNumber = 1 << (bitPosition - 1);
return (number | bitNumber);
intsetBit(int position, boolean value, int meta)
set Bit
if (value) {
    return meta | (1 << position);
return meta & ~(1 << position);
voidsetBit(int position, byte[] array)
Sets the bit in the array.
if (position < 0 || position >= array.length * 8) {
    throw new IllegalArgumentException("Position is invalid");
array[position / 8] |= (128 >> (position % 8));