Here you can find the source of bytesToBinString(byte[] bytes)
public static String bytesToBinString(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { public static String bytesToBinString(byte[] bytes) { char[] binChars = new char[bytes.length * 8]; int idx = 0; for (int i = 0; i < bytes.length; i++) { for (int bit = 7; bit >= 0; bit--, idx++) binChars[idx] = (((bytes[i] & 0xff) >> bit) & 0x01) != 0 ? '1' : '0'; }//from w w w . ja v a2 s . co m return new String(binChars); } }