Java Byte Array to Binary bytesToBinString(byte[] bytes)

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

Description

bytes To Bin String

License

Open Source License

Declaration

public static String bytesToBinString(byte[] bytes) 

Method Source Code

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

public class Main {
    public static String bytesToBinString(byte[] bytes) {
        char[] binChars = new char[bytes.length * 8];
        int idx = 0;
        for (int i = 0; i < bytes.length; i++) {
            for (int bit = 7; bit >= 0; bit--, idx++)
                binChars[idx] = (((bytes[i] & 0xff) >> bit) & 0x01) != 0 ? '1'
                        : '0';
        }//from w  w  w  .  ja v a2 s .  co  m
        return new String(binChars);
    }
}

Related

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