Android Utililty Methods Int Bit Set

List of utility methods to do Int Bit Set

Description

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

Method

intsetBit(int number, int count)
set Bit
return number | 0x01 << count;
intsetBit(int number, int count, boolean value)
set Bit
if (value) {
    return setBit(number, count);
return clearBit(number, count);
booleanisBitSet(int b, int bit)
is Bit Set
if (bit < 0 || bit >= 32)
    return false;
return (b & (1 << bit)) > 0;
booleanisBitSet(int number, int count)
is Bit Set
return (number & (0x01 << count)) > 0;
booleanisPowerOfTwo(int v)
returns true if v is a power of two or zero
return ((v & (v - 1)) == 0);
intclearBit(int number, int count)
clear Bit
return number | 0x01 << count;
booleancontains(int bit, int... options)
contains
return (bit & and(options)) == and(options);
Integer[]decode(int bits)
decode
int count = 0;
Integer[] buff = new Integer[32];
for (int i = 0; i < buff.length; i++) {
    if ((bits & (1 << i)) > 0) {
        buff[count++] = i;
Integer[] result = new Integer[count];
...
intnextHighestPowerOfTwo(int v)
returns the next highest power of two, or the current value if it's already a power of two or zero
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
...
inttoggleBit(int number, int count)
toggle Bit
return number | 0x01 << count;