List of utility methods to do Int Bit Set
int | setBit(int number, int count) set Bit return number | 0x01 << count;
|
int | setBit(int number, int count, boolean value) set Bit if (value) { return setBit(number, count); return clearBit(number, count); |
boolean | isBitSet(int b, int bit) is Bit Set if (bit < 0 || bit >= 32) return false; return (b & (1 << bit)) > 0; |
boolean | isBitSet(int number, int count) is Bit Set return (number & (0x01 << count)) > 0;
|
boolean | isPowerOfTwo(int v) returns true if v is a power of two or zero return ((v & (v - 1)) == 0);
|
int | clearBit(int number, int count) clear Bit return number | 0x01 << count;
|
boolean | contains(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]; ... |
int | nextHighestPowerOfTwo(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;
...
|
int | toggleBit(int number, int count) toggle Bit return number | 0x01 << count;
|