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[]fromHexString(String hexString)
Converts the hex string to a byte array.
if (hexString.length() % 2 != 0) {
    throw new NumberFormatException("odd number of digits: " + hexString);
byte[] bytes = new byte[hexString.length() / 2];
for (int i = 0; i < bytes.length; i++) {
    char d1 = hexString.charAt(i * 2);
    char d2 = hexString.charAt(i * 2 + 1);
    if (Character.digit(d1, 16) < 0 || Character.digit(d2, 16) < 0) {
...
byte[]fromHexString(String hexString)
Converts the hex-string back into an array of bytes
final int sl = hexString.length();
if ((sl % 2) != 0) {
    throw new IllegalArgumentException("hexString must be even length");
byte[] bytes = new byte[sl / 2];
for (int i = 0; i < sl; i += 2) {
    final int j = i / 2;
    byte high = valueOf(hexString.charAt(i));
...
int[]fromHexString(String hexString)
Transforms a color rgba hex string representation to its rgba components.
int[] rgba = new int[4];
int offset = 0;
if (hexString.length() == 10) {
    rgba[3] = Integer.parseInt(hexString.substring(2, 4), 16);
    offset = 2;
} else {
    rgba[3] = Integer.parseInt("FF", 16);
rgba[0] = Integer.parseInt(hexString.substring(2 + offset, 4 + offset), 16);
rgba[1] = Integer.parseInt(hexString.substring(4 + offset, 6 + offset), 16);
rgba[2] = Integer.parseInt(hexString.substring(6 + offset, 8 + offset), 16);
return rgba;
byte[]fromHexString(String in)
Convert a String of hex values into a byte[].
byte[] data = new byte[in.length() / 2];
for (int i = 0, j = 0; i < in.length();) {
    byte hi = fromHex(in.charAt(i++));
    byte lo = fromHex(in.charAt(i++));
    data[j++] = (byte) ((hi << 4) + lo);
return data;
byte[]fromHexString(String input)
from Hex String
if (input == null) {
    return null;
if ((input.length() & 1) == 1) {
    throw new IllegalArgumentException("The input must consist of an even number of hex digits");
char[] inputChars = input.toCharArray();
byte[] result = new byte[input.length() >> 1];
...
byte[]fromHexString(String input)
from Hex String
if (input == null || input.trim().length() == 0 || input.trim().length() % 2 != 0) {
    throw new IllegalArgumentException(
            "Input " + input + " is not valid. Must be not empty and length%2=0");
byte[] result = new byte[input.length() / 2];
for (int i = 0; i < input.length(); i += 2) {
    int intValue = Integer.valueOf(input.substring(i, i + 2), 16);
    result[i / 2] = (byte) (0x000000ff & intValue);
...
byte[]fromHexString(String input)
from Hex String
int n = input.length() / 2;
byte[] output = new byte[n];
int l = 0;
for (int k = 0; k < n; k++) {
    char c = input.charAt(l++);
    byte b = (byte) ((c >= 'a' ? (c - 'a' + 10) : (c - '0')) << 4);
    c = input.charAt(l++);
    b |= (byte) (c >= 'a' ? (c - 'a' + 10) : (c - '0'));
...
byte[]fromHexString(String s)
from Hex String
if (s.length() % 2 != 0)
    throw new IllegalArgumentException(s);
byte[] array = new byte[s.length() / 2];
for (int i = 0; i < array.length; i++) {
    int b = Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16);
    array[i] = (byte) (0xff & b);
return array;
...
byte[]fromHexString(String s)
from Hex String
if (s.length() % 2 == 1) {
    throw new IllegalArgumentException("Invalid length of string.");
byte[] data = new byte[s.length() / 2];
for (int i = 0; i < data.length; i++) {
    char c1 = s.charAt(i * 2);
    char c2 = s.charAt(i * 2 + 1);
    int n1 = HEX_STRING.indexOf(c1);
...
byte[]fromHexString(String s)
Convert a hex string to an unsigned byte array.
int stringLength = s.length();
if ((stringLength & 0x1) != 0) {
    throw new IllegalArgumentException("fromHexString requires an even number of hex characters");
byte[] bytes = new byte[stringLength / 2];
for (int i = 0, j = 0; i < stringLength; i += 2, j++) {
    int high = charToNibble(s.charAt(i));
    int low = charToNibble(s.charAt(i + 1));
...