Java Utililty Methods Binary Convert to

List of utility methods to do Binary Convert to

Description

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

Method

StringbinaryString(byte aByte, boolean prefix)
binary String
return binaryString(aByte, prefix ? "b0" : null);
byte[]binaryString2ByteArr(String binary)
binary String Byte Arr
StringBuffer str = new StringBuffer();
StringBuffer temp = new StringBuffer();
int length = binary.length();
str.append(binary);
byte[] result = null;
if (length >= 8 && (length % 8 == 0)) {
    result = new byte[length / 8];
} else {
...
intbinaryString2Long(String binString)
binary String Long
int value = 0;
int count = 1;
for (int i = binString.length(); i > 0; i--) {
    if (Integer.parseInt(binString.substring(i - 1, i)) == 1) {
        value = value + count;
    count = count * 2;
return value;
byte[]binaryStringToBytes(String binaryString)
binary String To Bytes
byte[] bytes = new byte[(int) Math.ceil(binaryString.length() / 8.0)];
for (int i = 0, j = 0, k = 7; i < binaryString.length(); i++) {
    byte bit = (byte) (binaryString.charAt(i) - '0');
    bytes[j] = (byte) (bytes[j] | bit << k);
    if (k == 0) {
        j++;
        k = 7;
    } else {
...
floatbinaryStringToFloat(String value)
binary String To Float
return (value.charAt(0) == '1' ? -1f : 1f) * Float.intBitsToFloat(Integer.parseInt(value.substring(1), 2));