Java Utililty Methods Byte to Binary

List of utility methods to do Byte to Binary

Description

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

Method

StringbyteToBin(byte[] bs)
byte To Bin
char[] cs = new char[bs.length * 9];
for (int i = 0; i < bs.length; ++i) {
    byte b = bs[i];
    int j = i * 9;
    cs[j] = (((b >>> 7 & 0x1) == 1) ? 49 : '0');
    cs[(j + 1)] = (((b >>> 6 & 0x1) == 1) ? 49 : '0');
    cs[(j + 2)] = (((b >>> 5 & 0x1) == 1) ? 49 : '0');
    cs[(j + 3)] = (((b >>> 4 & 0x1) == 1) ? 49 : '0');
...
StringbyteToBinary(byte value)
Return a binary string representation of the byte.
return String.format("%8s", Integer.toBinaryString(value & 0xFF)).replace(' ', '0');
StringbyteToBinaryStr(byte b)
byte To Binary Str
int v = b & 0xFF;
return byteToBinaryStr(v);
StringbyteToBinaryString(byte i)
byte To Binary String
StringBuilder result = new StringBuilder();
result.append(getBit(i, 8));
result.append(getBit(i, 7));
result.append(getBit(i, 6));
result.append(getBit(i, 5));
result.append(" ");
result.append(getBit(i, 4));
result.append(getBit(i, 3));
...
StringbyteToBinaryString(byte toString)
byte To Binary String
String string = "";
String s = String.format("%8s", Integer.toBinaryString(toString & 0xFF)).replace(' ', '0');
string += s;
return string;