Here you can find the source of toBinary(byte[] bytes)
public static String toBinary(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { public static String toBinary(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * Byte.SIZE); for (int i = 0; i < Byte.SIZE * bytes.length; i++) { sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0' : '1'); }/* ww w . j a va 2s .c om*/ return sb.toString(); } }