Java Bit String From toBitString(byte[] bytes)

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

Description

to Bit String

License

Mozilla Public License

Declaration

public static String toBitString(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Mozilla Public License 

public class Main {
    public static String toBitString(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            if (i != 0) {
                sb.append(" ");
            }//from w  ww .  j  a v  a2  s .c om
            sb.append(toString(bytes[i]));
        }
        return sb.toString();
    }

    public static String toString(byte b) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 8; i++) {
            sb.append(((b & 0x80) == 0x80) ? "1" : "0");
            b = (byte) (b << 1);
        }
        return sb.toString();
    }
}

Related

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