Java Byte to Binary byteToBin(byte[] bs)

Here you can find the source of byteToBin(byte[] bs)

Description

byte To Bin

License

Apache License

Declaration

public static String byteToBin(byte[] bs) 

Method Source Code

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

public class Main {
    public static String byteToBin(byte[] bs) {
        char[] cs = new char[bs.length * 9];
        for (int i = 0; i < bs.length; ++i) {
            byte b = bs[i];
            int j = i * 9;
            cs[j] = (((b >>> 7 & 0x1) == 1) ? 49 : '0');
            cs[(j + 1)] = (((b >>> 6 & 0x1) == 1) ? 49 : '0');
            cs[(j + 2)] = (((b >>> 5 & 0x1) == 1) ? 49 : '0');
            cs[(j + 3)] = (((b >>> 4 & 0x1) == 1) ? 49 : '0');
            cs[(j + 4)] = (((b >>> 3 & 0x1) == 1) ? 49 : '0');
            cs[(j + 5)] = (((b >>> 2 & 0x1) == 1) ? 49 : '0');
            cs[(j + 6)] = (((b >>> 1 & 0x1) == 1) ? 49 : '0');
            cs[(j + 7)] = (((b & 0x1) == 1) ? 49 : '0');
            cs[(j + 8)] = ',';
        }//from w  w w . j a v a  2 s. com
        return new String(cs);
    }
}

Related

  1. byteToBinary(byte value)
  2. byteToBinaryStr(byte b)
  3. byteToBinaryString(byte i)
  4. byteToBinaryString(byte toString)