Here you can find the source of toBitString(final StringBuilder sb, final byte value, final int count2)
public static void toBitString(final StringBuilder sb, final byte value, final int count2)
//package com.java2s; // and/or modify it under the terms of the GNU General Public License public class Main { public static void toBitString(final StringBuilder sb, final byte value, final int count2) { int count = count2; if (count > 8) { count = 8;/* w ww . j a v a 2 s .co m*/ } char[] data = new char[count]; for (int pos = 0; pos != count; ++pos) { if ((value & (1 << pos)) != 0) { data[count - pos - 1] = '1'; } else { data[count - pos - 1] = '0'; } } sb.append(data); } }