List of utility methods to do Binary to Hex
String | binaryToHex(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)); ... |
String | binaryToHex(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(); |
String | binaryToHex(byte[] data) binary To Hex return binaryToHex(data, 0, data.length);
|
char[] | binaryToHex(char[] binaryStr) binary To Hex return binaryToChar(binaryStr, 4);
|
char | binaryToHex(int binary) binary To Hex char ch = ' '; switch (binary) { case 0: ch = '0'; break; case 1: ch = '1'; break; ... |
String | BinaryToHexString(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; ... |
String | binaryToHexString(String binaryValue) binary To Hex String return "0x" + Integer.toHexString(Integer.parseInt(binaryValue, 2)).toUpperCase(); |
String | binToHex(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);
|
String | binToHex(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); |