Java Byte to Boolean Array byteToBooleanArray(byte b)

Here you can find the source of byteToBooleanArray(byte b)

Description

for byte b = "00000001 base 2", result[0] will be 1 (true) and result[7] will be 0 (false) boolean[] arr = byteToBooleanArray((byte)1); // binary: 00000001 System.out.println(arr[0]); // will display "true" System.out.println(arr[1]); // will display "false"

License

Open Source License

Declaration

public static boolean[] byteToBooleanArray(byte b) 

Method Source Code

//package com.java2s;
/*/*from  www  .  j  av a 2s .c om*/
 * gMix open source project - https://svs.informatik.uni-hamburg.de/gmix/
 * Copyright (C) 2012  Karl-Peter Fuchs
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * for byte b = "00000001 base 2", result[0] will be 1 (true) and result[7] will be 0 (false)
     * 
     * boolean[] arr = byteToBooleanArray((byte)1); // binary: 00000001
     * System.out.println(arr[0]); // will display "true" 
     * System.out.println(arr[1]); // will display "false"
     */
    public static boolean[] byteToBooleanArray(byte b) {
        boolean[] result = new boolean[8];
        for (int i = 0; i < result.length; i++)
            result[i] = (b & (1 << i)) != 0;
        return result;
    }
}

Related

  1. byteToBooleanArray(byte byteVal)
  2. byteToBooleanArray(byte input)