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

Stringbin2hex(byte[] arr)
Converts a byte array to hex string
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
    String str = Integer.toHexString((int) arr[i]);
    if (str.length() == 2)
        sb.append(str);
    if (str.length() < 2) {
        sb.append("0");
        sb.append(str);
...
Stringbin2Hex(byte[] b)
bin Hex
return bin2Hex(b, 0, b.length);
byte[]bin2Hex(byte[] bin)
Binary byte[] to Heximal byte[]
byte[] hex = new byte[2 * bin.length];
for (int i = 0, j = 0; i < bin.length; i++, j += 2) {
    int iByte = bin[i];
    if (iByte < 0)
        iByte += 256;
    int i4Bit = iByte >> 4;
    if (i4Bit < 10)
        hex[j] = (byte) ('0' + i4Bit);
...
Stringbin2hex(final byte[] b)
Simple binary-to-hexadecimal conversion.
if (b == null) {
    return "";
StringBuffer sb = new StringBuffer(2 * b.length);
for (int i = 0; i < b.length; i++) {
    int v = (256 + b[i]) % 256;
    sb.append(hex.charAt((v / 16) & 15));
    sb.append(hex.charAt((v % 16) & 15));
...
Stringbin2hex(final byte[] base)
binhex
if (base != null) {
    char[] c = new char[base.length * 2];
    int i = 0;
    for (byte b : base) {
        int j = b;
        j = j & 0xff; 
        c[i++] = TOHEX[j / 0x10];
        c[i++] = TOHEX[j % 0x10];
...
intbin2hex(int digit)
binhex
final int isLessOrEqual9 = (digit - 10) >> 31;
final int bin2hexAsciiDistance = 48 + ((~isLessOrEqual9) & 39);
return digit + bin2hexAsciiDistance;
Stringbin2Hex(String bin)
bin Hex
int intVal = parseBin(bin);
return normalizeNumber(Integer.toHexString(intVal), bin.length() / 4);
Stringbin2hex(String bin)
binhex
char[] digital = "0123456789ABCDEF".toCharArray();
StringBuffer sb = new StringBuffer("");
byte[] bs = bin.getBytes();
int bit;
for (int i = 0; i < bs.length; i++) {
    bit = (bs[i] & 0x0f0) >> 4;
    sb.append(digital[bit]);
    bit = bs[i] & 0x0f;
...
Stringbin2hex(String str)
binhex
String s = dec2hex(Integer.parseInt(str, 2));
return s;
StringbinaryString2hexString(String bString)
binary Stringhex String
if (bString == null || bString.equals("") || bString.length() % 8 != 0)
    return null;
StringBuffer tmp = new StringBuffer();
int iTmp = 0;
for (int i = 0; i < bString.length(); i += 4) {
    iTmp = 0;
    for (int j = 0; j < 4; j++) {
        iTmp += Integer.parseInt(bString.substring(i + j, i + j + 1)) << (4 - j - 1);
...