Java Byte Array to Binary bytesToBinary(byte[] b, int byteLength)

Here you can find the source of bytesToBinary(byte[] b, int byteLength)

Description

bytes To Binary

License

Open Source License

Declaration

public static String bytesToBinary(byte[] b, int byteLength) 

Method Source Code

//package com.java2s;

public class Main {
    public static String bytesToBinary(byte[] b, int byteLength) {
        int i = bytesToInt(b);
        String binString = Integer.toBinaryString(i);
        while (binString.length() < byteLength * 8) {
            binString = "0" + binString;
        }/*  w  ww . j av  a 2 s . co  m*/
        return binString;
    }

    public static int bytesToInt(byte[] b) {

        int mask = 0xff;
        int temp = 0;
        int n = 0;
        for (int i = 0; i < b.length; i++) {
            n <<= 8;
            temp = b[i] & mask;
            n |= temp;
        }
        return n;
    }
}

Related

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