Here you can find the source of getBitString(java.nio.ByteBuffer buffer, int lenBits)
public static String getBitString(java.nio.ByteBuffer buffer, int lenBits)
//package com.java2s; public class Main { public static String getBitString(java.nio.ByteBuffer buffer, int lenBits) { String s = ""; int len = (int) Math.ceil(lenBits / (double) Byte.SIZE); if (null != buffer && buffer.remaining() >= len) { byte[] dest = new byte[len]; buffer.get(dest, 0, len);/*from w w w.j av a 2s.c o m*/ char[] bits = new char[lenBits]; for (int i = 0; i < lenBits; i++) { int mask = 0x1 << (Byte.SIZE - (i % Byte.SIZE) - 1); // U+0030 : unicode zero // U+0031 : unicode one bits[i] = (mask & dest[i / Byte.SIZE]) == 0 ? '\u0030' : '\u0031'; } s = new String(bits); } return s; } }