Java Utililty Methods Binary to Hex

List of utility methods to do Binary to Hex

Description

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

Method

StringbinaryToHex(byte[] ba)
binary To Hex
if (ba == null || ba.length == 0) {
    return null;
StringBuilder sb = new StringBuilder(ba.length * 2);
String hexNumber;
for (int x = 0, sz = ba.length; x < sz; x++) {
    hexNumber = "0" + Integer.toHexString(0xff & ba[x]);
    sb.append(hexNumber.substring(hexNumber.length() - 1));
...
StringbinaryToHex(byte[] bytes)
binary To Hex
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
    sb.append(String.format("%02x", b & 0xff));
return sb.toString();
StringbinaryToHex(byte[] data)
binary To Hex
return binaryToHex(data, 0, data.length);
char[]binaryToHex(char[] binaryStr)
binary To Hex
return binaryToChar(binaryStr, 4);
charbinaryToHex(int binary)
binary To Hex
char ch = ' ';
switch (binary) {
case 0:
    ch = '0';
    break;
case 1:
    ch = '1';
    break;
...
StringBinaryToHexString(byte[] bytes)
Binary To Hex String
String result = "";
String hex = "";
for (int i = 0; i < bytes.length; i++) {
    hex = String.valueOf(hexStr.charAt((bytes[i] & 0xF0) >> 4));
    hex += String.valueOf(hexStr.charAt(bytes[i] & 0x0F));
    result += hex;
return result;
...
StringbinaryToHexString(String binaryValue)
binary To Hex String
return "0x" + Integer.toHexString(Integer.parseInt(binaryValue, 2)).toUpperCase();
StringbinToHex(byte[] bin)
bin To Hex
StringBuffer buf = new StringBuffer();
for (int i = 0; i < bin.length; i++) {
    int value = bin[i] < 0 ? bin[i] + 256 : bin[i]; 
    buf.append(hexdigits.charAt(value / 16));
    buf.append(hexdigits.charAt(value % 16));
return buf.toString();
char[]binToHex(byte[] bytes)
bin To Hex
return binToHex(bytes, 0, bytes.length);
StringbinToHex(byte[] data)
Converts an array of bytes into an hexadecimal string
char[] hexChars = new char[data.length * 2];
for (int j = 0; j < data.length; j++) {
    int v = data[j] & 0xFF;
    hexChars[j * 2] = hexArray[v >>> 4];
    hexChars[j * 2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);