List of utility methods to do Boolean to Bit
byte | booleanToBit(boolean b) boolean To Bit if (b) return 1; else return 0; |
byte | booleanToBit(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 { ... |
int | booleanToBitflags(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; ... |