Java Utililty Methods Binary Encode

List of utility methods to do Binary Encode

Description

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

Method

byte[]toBinaryID(final String id)
to Binary ID
final int length = id.length();
final byte[] result = new byte[length];
for (int i = 0; i < length; i++) {
    result[i] = Byte.parseByte(Character.toString(id.charAt(i)));
return result;
StringtoBinaryIeee754String(long decimal)
to Binary Ieee String
String binary = Long.toBinaryString(decimal);
StringBuilder result = new StringBuilder(binary);
for (long i = binary.length(); i < 32; i++) {
    result.insert(0, "0");
result.insert(9, " ");
result.insert(1, " ");
return result.toString();
...
int[]toBinaryIntArray(byte[] bytes, int bitOffset, int bitCount)
to Binary Int Array
int bitReadIndex = bitOffset;
int byteReadIndex = bitReadIndex / 8;
int bitWriteIndex = 0;
int[] result = new int[bitCount];
while (bitWriteIndex < bitCount) {
    int value = (bytes[byteReadIndex] & 0xFF);
    int bitRelative = bitReadIndex - (8 * byteReadIndex);
    result[bitWriteIndex++] = Integer.rotateRight(value, 7 - bitRelative) & 0x01;
...
StringtoBinaryName(String className)
to Binary Name
return dotsToSlashes(className) + ".class";
StringtoBinaryString(boolean[] array)
to Binary String
char[] rawArr = new char[array.length];
for (int i = 0; i < rawArr.length; i++) {
    rawArr[i] = toBinaryChar(array[i]);
return new String(rawArr);
StringtoBinaryString(byte b)
NOTE the SDK supplies a Integer.toBinaryString but it is not formatted to a standard number of chars so it was not a good option.
StringBuffer sb = new StringBuffer();
sb.append((b >> 7 & 0x01));
sb.append((b >> 6 & 0x01));
sb.append((b >> 5 & 0x01));
sb.append((b >> 4 & 0x01));
sb.append((b >> 3 & 0x01));
sb.append((b >> 2 & 0x01));
sb.append((b >> 1 & 0x01));
...
StringtoBinaryString(byte b)
to Binary String
String str = "";
for (int i = 7; i >= 0; i--)
    str += ((b & (1 << i)) != 0) ? "1" : "0";
return str;
StringtoBinaryString(byte... bytes)
to Binary String
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
    if (sb.length() > 0) {
        sb.append(' ');
    sb.append(Integer.toBinaryString(256 + b));
return sb.toString();
...
StringtoBinaryString(byte[] array)
to Binary String
StringBuffer sb = new StringBuffer();
for (byte b : array) {
    sb.append(toBinaryString(b));
    sb.append(" ");
return sb.toString();
StringtoBinaryString(byte[] bytes)
Translate the given byte array into a string of 1s and 0s
StringBuilder buffer = new StringBuilder();
for (byte b : bytes) {
    String bin = Integer.toBinaryString(0xFF & b);
    bin = bin.substring(0, Math.min(bin.length(), 8));
    for (int j = 0; j < 8 - bin.length(); j++) {
        buffer.append('0');
    buffer.append(bin);
...