Java Binary Encode toBinString(byte[] byteArray)

Here you can find the source of toBinString(byte[] byteArray)

Description

to Bin String

License

Apache License

Declaration

public static String toBinString(byte[] byteArray) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private final static int SIZE_IN_BITS = 8;

    public static String toBinString(byte[] byteArray) {
        StringBuilder sb = new StringBuilder();
        for (int byteNum = byteArray.length - 1; byteNum >= 0; byteNum--) {
            for (int bitNum = SIZE_IN_BITS - 1; bitNum >= 0; bitNum--) {
                if (bitAt(bitNum, byteArray[byteNum])) {
                    sb.append("1");
                } else {
                    sb.append("0");
                }/*from  www . j a  va2 s . c om*/
            }
        }
        return sb.toString();
    }

    public static boolean bitAt(int offset, byte aByte) {
        return (aByte & (1 << offset)) != 0;
    }
}

Related

  1. toBinFromHexChar(final char hex)
  2. toBinFromOct(final String octSymbols)
  3. toBinFromOctChar(final char oct)
  4. toBinString(byte b)
  5. toBinString(byte value)
  6. toBinString(int val, int minLength)