Java Boolean Convert to booleanArrayToInt(boolean[] in)

Here you can find the source of booleanArrayToInt(boolean[] in)

Description

convert an array of booleans - one ber bit to an int

License

Apache License

Parameter

Parameter Description
in a parameter

Declaration

public static int booleanArrayToInt(boolean[] in) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   w  ww.java2s . c o m
     * convert an array of booleans - one ber bit
     * to an int
     * @param in
     * @return
     */
    public static int booleanArrayToInt(boolean[] in) {
        if (in.length > 32)
            throw new IllegalArgumentException("no more than 32 bits in an int");
        int index = 1;
        int ret = 0;
        for (int i = 0; i < in.length; i++) {
            if (in[i])
                ret |= index;
            index <<= 1;
        }
        return ret;
    }
}

Related

  1. boolean2byte(boolean b)
  2. boolean2double(boolean b)
  3. boolean2long(boolean b)
  4. booleanArrayToBitString(final boolean[] booleanArray)
  5. booleanArrayToBytes(boolean[] input)
  6. booleanArrayToIntIndexes(boolean[] arrb)
  7. booleanArrayToString(boolean[] array)
  8. booleanArrayToString(boolean[] b, String delim)
  9. booleanArrayToString(boolean[] ba)