Java Bits Convert to bitArray2byte(boolean[] array)

Here you can find the source of bitArray2byte(boolean[] array)

Description

bit Arraybyte

License

Apache License

Declaration

public static byte bitArray2byte(boolean[] array) 

Method Source Code

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

public class Main {

    public static byte bitArray2byte(boolean[] array) {
        if (array == null || array.length != 8) {
            throw new RuntimeException("Bad bit array");
        }//from   w  w  w  .j  a v  a2  s  .  com
        byte b = 0;
        for (int i = 0; i <= 7; i++) {
            if (array[i]) {
                // 0000 0001
                int nn = (1 << (7 - i));
                b += nn;
            }
        }
        return b;
    }
}

Related

  1. bit(byte[] h, int i)
  2. bit(int a, int b)
  3. bit(int row, int col)
  4. BIT(int x)
  5. bitarrayShiftAndFill(byte[] data, int length, int shift, byte first, byte last)
  6. bitArrayToByte(byte[] bytes)
  7. BitArrayToString(Boolean[] asciiBinary)
  8. bitboardToString(final long l)