Java Utililty Methods Bits to Int

List of utility methods to do Bits to Int

Description

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

Method

intbitsToInt(boolean[] pBits)
Gets the integer represented by a bit string (as an array).
int vInt = 0;
int vIntBit = 0;
for (int i = pBits.length - 1; i >= 0; i--) {
    if (pBits[i]) {
        vInt |= (1 << vIntBit);
    vIntBit++;
return vInt;
intbitsToInt(String bits, int min, int max)
Turns the bit string back into an integer.
double j = 0;
for (int i = 0; i < bits.length(); i++) {
    if (bits.charAt(i) == '1') {
        j = j + Math.pow(2, bits.length() - i - 1);
j += min;
return Math.min((int) j, max);
...
int[]bitsToIntArray(String bits, int min, int max, int numBits, int size)
Turns a bit string (0s and 1s) into an integer array.
int ret[] = new int[size];
for (int k = 0; k < size; k++) {
    int start = numBits * k;
    double j = 0;
    for (int i = start; i < start + numBits; i++) {
        if (bits.charAt(i) == '1') {
            j = j + Math.pow(2, start + numBits - i - 1);
    j += min;
    ret[k] = (Math.min((int) j, max));
return ret;