Java Bit String From toBitString(byte[] data)

Here you can find the source of toBitString(byte[] data)

Description

to Bit String

License

LGPL

Declaration

public static String toBitString(byte[] data) 

Method Source Code

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

Related

  1. toBitsArray(byte[] bytes, int bitCount)
  2. toBitString(byte value)
  3. toBitString(byte[] bytes)
  4. toBitString(byte[] bytes)
  5. toBitString(byte[] bytes, final int digitsPerGroup, final String groupSeparator)
  6. toBitString(final byte n)
  7. toBitString(final byte[] b)
  8. toBitString(final byte[] b)
  9. toBitString(final double d)