Java Boolean to Bit booleanToBitflags(boolean[] flags)

Here you can find the source of booleanToBitflags(boolean[] flags)

Description

boolean To Bitflags

License

Open Source License

Declaration

public static int booleanToBitflags(boolean[] flags) 

Method Source Code

//package com.java2s;

public class Main {
    public static int booleanToBitflags(boolean[] flags) {
        if (flags.length > 31)
            throw new IllegalArgumentException(
                    "You cannot store more than 31 bits on an int!");
        int n = 0;
        for (int i = 0; i < flags.length; i++) {
            if (flags[i])
                n += (1 << i);//from  ww  w .ja va2  s.  c  om
        }
        return n;
    }
}

Related

  1. booleanToBit(boolean b)
  2. booleanToBit(final byte value, final int bitNbr, final boolean state)