Java ByteBuffer Get getBitString(java.nio.ByteBuffer buffer, int lenBits)

Here you can find the source of getBitString(java.nio.ByteBuffer buffer, int lenBits)

Description

get Bit String

License

Open Source License

Declaration

public static String getBitString(java.nio.ByteBuffer buffer,
            int lenBits) 

Method Source Code

//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;
    }
}

Related

  1. getAsIntArray(ByteBuffer yuv, int size)
  2. getAttrs(Map fields)
  3. getBatch(ByteBuffer bb)
  4. getBigDecimalFromByteBuffer( ByteBuffer bytebuf, int start, int length, int scale)
  5. getBit(ByteBuffer in, int pos)
  6. getBoolean(ByteBuffer b)
  7. getBoolean(ByteBuffer bb)
  8. getBoolean(ByteBuffer bytes)
  9. getBoolean(java.nio.ByteBuffer buffer)