Java Utililty Methods Byte to Hex

List of utility methods to do Byte to Hex

Description

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

Method

Stringbytes2hex(byte[] binput)
byteshex
StringBuffer s = new StringBuffer(binput.length * 2);
for (int i = 0; i < binput.length; i++) {
    byte b = binput[i];
    s.append(HEXCHARS[(b & 0xF0) >> 4]);
    s.append(HEXCHARS[b & 0x0F]);
return s.toString();
Stringbytes2hex(byte[] bts)
byteshex
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
int j = bts.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
    byte byte0 = bts[i];
    str[k++] = hexDigits[byte0 >>> 4 & 0xf];
    str[k++] = hexDigits[byte0 & 0xf];
...
Stringbytes2hex(byte[] bytes)
byte[] array to hex conversion.
char[] ca = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
    int v = bytes[i] & 0xff;
    ca[i * 2] = hexArray[v >>> 4];
    ca[i * 2 + 1] = hexArray[v & 0x0f];
return new String(ca);
Stringbytes2hex(byte[] bytes)
This method converts byte stream to a hex string
if (bytes != null) {
    StringBuilder hexString = new StringBuilder();
    for (byte b : bytes) {
        String strHex = Integer.toHexString(b & 0xFF);
        if (strHex.length() < 2) {
            hexString.append(0);
        hexString.append(strHex);
...
Stringbytes2hex(byte[] bytes)
byteshex
StringBuilder hex = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    byte b = bytes[i];
    boolean negative = false;
    if (b < 0)
        negative = true;
    int bAbs = Math.abs(b);
    if (negative)
...
StringBytes2HexString(byte[] b)
Bytes Hex String
byte[] buff = new byte[2 * b.length];
for (int i = 0; i < b.length; i++) {
    buff[2 * i] = hex[(b[i] >> 4) & 0x0f];
    buff[2 * i + 1] = hex[b[i] & 0x0f];
return new String(buff);
StringbytesToHex(byte b)
bytes To Hex
return bytesToHex(new byte[] { b });
StringbytesToHexs(byte[] buf)
bytes To Hexs
if (buf == null)
    return "";
StringBuffer sb = new StringBuffer();
for (byte b : buf) {
    sb.append(byteToHex(b));
    sb.append(",");
return sb.toString();
...
StringbytesToLowerCaseHex(byte[] data)
bytes To Lower Case Hex
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
    int halfbyte = (data[i] >>> 4) & 0x0F;
    int two_halfs = 0;
    do {
        if ((0 <= halfbyte) && (halfbyte <= 9))
            buf.append((char) ('0' + halfbyte));
        else
...
StringbytesToModHex(final byte[] inputBytes)
bytes To Mod Hex
assert inputBytes != null;
assert MOD_HEX_DIGITS != null;
assert MOD_HEX_DIGITS.length == 16;
StringBuilder modHexOutput = new StringBuilder(inputBytes.length * 2);
for (byte b : inputBytes) {
    int msb = (b >> 4) & 0xf;
    int lsb = b & 0xf;
    assert msb >= 0;
...