Java Utililty Methods Byte to Hex String

List of utility methods to do Byte to Hex String

Description

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

Method

StringbyteToHexString(byte num)

Converts the given byte value to hex string.

return toHexString(byteToUnsignedLong(num), '0', 2, 2);
StringbyteToHexString(byte src)
byte To Hex String
StringBuilder stringBuilder = new StringBuilder("");
int v = src & 0xFF;
String hv = Integer.toHexString(v);
if (hv.length() < 2) {
    stringBuilder.append(0);
stringBuilder.append(hv);
return stringBuilder.toString();
...
StringbyteToHexString(byte value)
Converts the given byte into an hex string.
final StringBuilder hex = new StringBuilder(2);
byte b = value;
hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
return hex.toString();
StringbyteToHexString(byte value)
byte To Hex String
String temp = null;
switch ((value & 0xF0) >> 4) {
case 0:
    temp = "0";
    break;
case 1:
    temp = "1";
    break;
...
StringbyteToHexString(byte[] b)
byte To 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);
StringbyteToHexString(byte[] b)
byte To Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
    String hex = Integer.toHexString(b[i] & 0xFF);
    if (hex.length() == 1) {
        hex = '0' + hex;
    hexString.append(hex.toUpperCase());
return hexString.toString();
StringbyteToHexString(byte[] bytes)
This methos used to convert byte array to hex string
StringBuffer sb = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    int v = bytes[i] & 0xff;
    if (v < 16) {
        sb.append('0');
    sb.append(Integer.toHexString(v));
return sb.toString().toUpperCase();
StringbyteToHexString(byte[] bytes, int start, int end)
Given an array of bytes it will convert the bytes to a hex string representation of the bytes
if (bytes == null) {
    throw new IllegalArgumentException("bytes == null");
StringBuilder s = new StringBuilder();
for (int i = start; i < end; i++) {
    s.append(String.format("%02x", bytes[i]));
return s.toString();
...
StringbyteToHexString(byte[] bytes, int start, int end)
Given an array of bytes it will convert the bytes to a hex string representation of the bytes
if (bytes == null) {
    throw new IllegalArgumentException("bytes == null");
StringBuilder s = new StringBuilder();
for (int i = start; i < end; i++) {
    s.append(String.format("%02x", bytes[i]));
return s.toString();
...
StringbyteToHexString(byte[] data)
Convert the given byte array to its hex representation.
StringBuilder sb = new StringBuilder();
for (byte b : data) {
    sb.append(String.format("%02X", b));
return sb.toString();