Here you can find the source of toBitString(byte[] data)
public static String toBitString(byte[] data)
//package com.java2s; //License from project: LGPL public class Main { public static String toBitString(byte[] data) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length * 8; i++) { sb.append(getBit(data, i));//from ww w.j a va 2s. c om } return sb.toString(); } public static byte getBit(byte[] data, long pos) { int posByte = (int) (pos / 8); int posBit = (int) (pos % 8); byte valByte = data[posByte]; return getBit(valByte, posBit); } public static byte getBit(byte data, int pos) { return (byte) (data >> (8 - (pos + 1)) & 0x0001); } }