Java Byte Array to Binary bytesToBits(byte[] buf)

Here you can find the source of bytesToBits(byte[] buf)

Description

bytes To Bits

License

Open Source License

Declaration

public static String bytesToBits(byte[] buf) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static String bytesToBits(byte[] buf) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < buf.length; i++) {
            sb.append(byteToBits(buf[i]));
            sb.append(",");
        }//from  w  ww. ja  v  a  2 s  .  co m
        return sb.toString();
    }

    public static String byteToBits(byte b) {
        return "" + (byte) ((b >> 7) & 0x1) + (byte) ((b >> 6) & 0x1) + (byte) ((b >> 5) & 0x1)
                + (byte) ((b >> 4) & 0x1) + (byte) ((b >> 3) & 0x1) + (byte) ((b >> 2) & 0x1)
                + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1);
    }
}

Related

  1. bytes2Binary(byte[] b)
  2. bytes2Binary(byte[] bytes)
  3. bytesToBinary(byte[] b, int byteLength)
  4. bytesToBinString(byte[] bytes)
  5. bytesToBits(byte[] b)