Here you can find the source of toBitString(byte[] bytes)
public static String toBitString(byte[] bytes)
//package com.java2s; //License from project: Mozilla Public License public class Main { public static String toBitString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { if (i != 0) { sb.append(" "); }//from w ww . j a v a2 s .c om sb.append(toString(bytes[i])); } return sb.toString(); } public static String toString(byte b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 8; i++) { sb.append(((b & 0x80) == 0x80) ? "1" : "0"); b = (byte) (b << 1); } return sb.toString(); } }