Here you can find the source of toBinString(byte[] byteArray)
public static String toBinString(byte[] byteArray)
//package com.java2s; //License from project: Apache License public class Main { private final static int SIZE_IN_BITS = 8; public static String toBinString(byte[] byteArray) { StringBuilder sb = new StringBuilder(); for (int byteNum = byteArray.length - 1; byteNum >= 0; byteNum--) { for (int bitNum = SIZE_IN_BITS - 1; bitNum >= 0; bitNum--) { if (bitAt(bitNum, byteArray[byteNum])) { sb.append("1"); } else { sb.append("0"); }/*from www . j a va2 s . c om*/ } } return sb.toString(); } public static boolean bitAt(int offset, byte aByte) { return (aByte & (1 << offset)) != 0; } }