Here you can find the source of booleanToByteBitflags(boolean[] flags)
public static byte booleanToByteBitflags(boolean[] flags)
//package com.java2s; public class Main { public static byte booleanToByteBitflags(boolean[] flags) { if (flags.length > 8) throw new IllegalArgumentException( "You cannot store more than 8 bits on a byte!"); byte n = 0; for (int i = 0; i < flags.length; i++) { if (flags[i]) n += (1 << i);//from w ww .j ava 2s. co m } return n; } }