Here you can find the source of bytesToBinary(byte[] b, int byteLength)
public static String bytesToBinary(byte[] b, int byteLength)
//package com.java2s; public class Main { public static String bytesToBinary(byte[] b, int byteLength) { int i = bytesToInt(b); String binString = Integer.toBinaryString(i); while (binString.length() < byteLength * 8) { binString = "0" + binString; }/* w ww . j av a 2 s . co m*/ return binString; } public static int bytesToInt(byte[] b) { int mask = 0xff; int temp = 0; int n = 0; for (int i = 0; i < b.length; i++) { n <<= 8; temp = b[i] & mask; n |= temp; } return n; } }