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

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

Description

bytes To Bits

License

Apache License

Declaration

public static String bytesToBits(byte[] b) 

Method Source Code

//package com.java2s;
//PduUtils is distributed under the terms of the Apache License version 2.0

public class Main {
    public static String bytesToBits(byte[] b) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < b.length; i++) {
            String bits = Integer.toBinaryString(b[i] & 0xFF);
            while (bits.length() < 8) {
                bits = "0" + bits;
            }/*from w  w w .j  a  va 2  s. c  o m*/
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(bits);
        }
        return sb.toString();
    }
}

Related

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