Java Utililty Methods Byte Array to Binary

List of utility methods to do Byte Array to Binary

Description

The list of methods to do Byte Array to Binary are organized into topic(s).

Method

Stringbytes2Binary(byte[] b)
bytes Binary
StringBuilder str = new StringBuilder();
for (int i = 0; i < b.length; i++) {
    if (i > 0)
        str.append('_');
    str.append(byte2Binary(b[i]));
return str.toString();
Stringbytes2Binary(byte[] bytes)
bytes Binary
StringBuffer sb = new StringBuffer();
for (byte b : bytes) {
    sb.append(Integer.toBinaryString(b));
return sb.toString();
StringbytesToBinary(byte[] b, int byteLength)
bytes To Binary
int i = bytesToInt(b);
String binString = Integer.toBinaryString(i);
while (binString.length() < byteLength * 8) {
    binString = "0" + binString;
return binString;
StringbytesToBinString(byte[] bytes)
bytes To Bin String
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';
return new String(binChars);
StringbytesToBits(byte[] b)
bytes To Bits
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;
    if (i > 0) {
        sb.append(" ");
...
StringbytesToBits(byte[] buf)
bytes To Bits
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
    sb.append(byteToBits(buf[i]));
    sb.append(",");
return sb.toString();