Java Utililty Methods Hex Convert To

List of utility methods to do Hex Convert To

Description

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

Method

byte[]fromHex(String hex)
from Hex
char[] hexChars = hex.toCharArray();
int n = hexChars.length;
byte[] bytes = new byte[(int) Math.ceil(n / 2.0)];
for (int c = 0; c < n; c += 2) {
    byte i = (byte) (charToNum(hexChars[c]) << 4);
    byte j = (c + 1 < n) ? charToNum(hexChars[c + 1]) : 0;
    bytes[c / 2] = (byte) (i + j);
return bytes;
StringfromHex(String hex)
from Hex
return new String(toByte(hex));
byte[]fromHex(String hex)
from Hex
if (hex != null && hex.length() > 1) {
    try {
        byte bytes[] = new byte[hex.length() / 2];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte) Integer.parseInt(hex.substring(i << 1, (i << 1) + 2), 16);
        return bytes;
    } catch (Throwable e) {
...
byte[]fromHex(String hex)
from Hex
final int len = hex.length();
byte[] out = new byte[len >> 1];
final char[] chars = hex.toCharArray();
for (int i = 0; i < out.length; i++) {
    final byte i1 = hexCharToByte(chars[i << 1]);
    final byte i2 = hexCharToByte(chars[(i << 1) + 1]);
    out[i] = (byte) ((i1 << 4) + i2);
return out;
byte[]fromHex(String hex)
from Hex
byte[] res = new byte[hex.length() / 2];
for (int i = 0; i < res.length; i++) {
    res[i] = (byte) ((fromHexShort(hex.charAt(i * 2)) << 4) + fromHexShort(hex.charAt(i * 2 + 1)));
return res;
byte[]fromHex(String hex)
from Hex
int len = hex.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
    data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
            + Character.digit(hex.charAt(i + 1), 16));
return data;
byte[]fromHex(String hex)
from Hex
return fromHex(hex, '0');
byte[]fromHex(String hexBytes)
from Hex
byte[] result = new byte[(hexBytes.length() + 1) / 2];
int n = 0;
for (char c : hexBytes.toCharArray()) {
    int digit = Character.digit(c, 16);
    if (digit == -1)
        throw new IllegalArgumentException("Not a valid hex digit: " + c);
    int index = n >>> 1;
    if ((n & 1) == 0) {
...
byte[]fromHex(String hexData)
from Hex
byte[] result = new byte[(hexData.length() + 1) / 2];
String hexNumber = null;
int stringOffset = 0;
int byteOffset = 0;
while (stringOffset < hexData.length()) {
    hexNumber = hexData.substring(stringOffset, stringOffset + 2);
    stringOffset += 2;
    result[(byteOffset++)] = ((byte) Integer.parseInt(hexNumber, 16));
...
byte[]fromHex(String hexStr)
from Hex
int byteSize = 2;
byte[] result = new byte[hexStr.length() / byteSize];
for (int i = 0; i < hexStr.length() / byteSize; i++) {
    String current = hexStr.substring(byteSize * i, byteSize * (i + 1));
    result[i] = (byte) Integer.parseInt(current, 16);
return result;