Java Utililty Methods Boolean to Bit

List of utility methods to do Boolean to Bit

Description

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

Method

bytebooleanToBit(boolean b)
boolean To Bit
if (b)
    return 1;
else
    return 0;
bytebooleanToBit(final byte value, final int bitNbr, final boolean state)
Sets a specific bit in the input byte.
if (bitNbr < 0 || bitNbr > 7) {
    throw new IllegalArgumentException("Parameter bitNbr is out of range (0-7)");
final byte convertedBit = BIT[bitNbr];
byte result = value;
if (state) {
    result |= convertedBit;
} else {
...
intbooleanToBitflags(boolean[] flags)
boolean To Bitflags
if (flags.length > 31)
    throw new IllegalArgumentException("You cannot store more than 31 bits on an int!");
int n = 0;
for (int i = 0; i < flags.length; i++) {
    if (flags[i])
        n += (1 << i);
return n;
...