Java Utililty Methods Bit Get

List of utility methods to do Bit Get

Description

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

Method

intbitAt(byte b, int pos)
bit At
int i = 1 << 7 - pos;
return (b & i & 0xFF) > 0 ? 1 : 0;
booleanbitAt(int offset, byte aByte)
Examine the values of bits within a byte.
return (aByte & (1 << offset)) != 0;
booleanbitAt(int offset, byte aByte)
bit At
return (aByte & (1 << offset)) != 0;
intbits(int i)
bits
return 32 - Integer.numberOfLeadingZeros(i);
intbits(int i)
Compute the integer logarithms (ceil(log(x+1)) of a value
return 32 - Integer.numberOfLeadingZeros(i);
intbits(int n, int offset, int length)
Bit play
http://stackoverflow.com/questions/11419501/converting-bits-in-to-integer
n = n >> (31 - offset - length);
int mask = ~(-1 << length);
return n & mask;
Stringbits(int value, int c)
bits
StringBuffer sb = new StringBuffer();
for (int i = c - 1; i >= 0; i--) {
    int bv = (value >>> (8 * i)) & 0xff;
    sb.append('[');
    for (int j = 7; j >= 0; j--) {
        sb.append((bv & (1 << j)) > 0 ? '1' : '0');
    sb.append(']');
...
intbits(int value, int first, int last)
Get the specified bits from the specified value.
return (value >> last) & mask(first - last + 1);
intbits(long maxValue)
bits
int bits = 0;
while (maxValue != 0) {
    bits++;
    maxValue >>>= 1;
return bits;
longbits(long value, int sb, int eb)
Extracts a bit range from a long value
value >>>= eb;
sb -= eb - 1;
long mask = (1L << sb) - 1;
value &= mask;
return value;