Here you can find the source of toBooleanA(byte[] data)
public static boolean[] toBooleanA(byte[] data)
//package com.java2s; //License from project: Open Source License public class Main { public static boolean[] toBooleanA(byte[] data) { // Advanced Technique: Extract the boolean array's length // from the first four bytes in the char array, and then // read the boolean array. // ---------- if (data == null || data.length < 4) return null; // ---------- int len = toInt(new byte[] { data[0], data[1], data[2], data[3] }); boolean[] bools = new boolean[len]; // ----- pack bools: for (int i = 0, j = 4, k = 7; i < bools.length; i++) { bools[i] = ((data[j] >> k--) & 0x01) == 1; if (k < 0) { j++;// w ww .j a v a 2s .c o m k = 7; } } // ---------- return bools; } public static int toInt(byte[] data) { if (data == null || data.length != 4) return 0x0; // ---------- return (int) ( // NOTE: type cast not necessary for int (0xff & data[0]) << 24 | (0xff & data[1]) << 16 | (0xff & data[2]) << 8 | (0xff & data[3]) << 0); } }