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

intfromHex(String s, boolean hexIsDefault)
from Hex
int radix = hexIsDefault ? 16 : 10;
int res = 0;
int pos = 0;
int sign = 1;
if (s.charAt(0) == '-') {
    pos += 1;
    sign = -1;
if ((!hexIsDefault) && s.regionMatches(pos, hexReprPrefix, 0, 2)) {
    pos += 2;
    radix = 16;
int max = s.length();
for (; pos < max; pos++) {
    int d = toDigit(s.charAt(pos));
    if ((d < 0) || (radix <= d))
        return res;
    res = res * radix + d;
return res * sign;
byte[]fromHex(String src)
from Hex
String[] hex = src.split(" ");
byte[] b = new byte[hex.length];
for (int i = 0; i < hex.length; i++) {
    b[i] = (byte) (Integer.parseInt(hex[i], 16) & 0xff);
return b;
byte[]fromHex(String str)
Converts a hex string into an array of bytes.
char[] chars = str.toCharArray();
byte[] bytes = new byte[chars.length / 2];
for (int i = 0; i < chars.length; i += 2) {
    int j = i >> 1;
    int b = 0;
    for (int k = 0; k < 2; k++) {
        int ch = chars[i + k];
        switch (ch) {
...
StringfromHex(String str)
from Hex
StringBuffer buff = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) == '\\') {
        buff.append(Integer.valueOf(str.substring(i + 4, i + 6), 16));
    } else {
        buff.append(str.charAt(i));
return buff.toString();
byte[]fromHex(String string)
from Hex
if ((string.length() & 1) != 0) {
    throw new IllegalArgumentException("String length must be even");
int rl = string.length() / 2;
byte[] result = new byte[rl];
for (int i = 0; i < rl; i++) {
    String hex = string.substring(i * 2, i * 2 + 2);
    result[i] = (byte) Integer.parseInt(hex, 16);
...
byte[]fromHex(String text)
Utility method which converts a hex string to a byte[]
byte[] result = new byte[text.length() / 2];
for (int i = 0; i < result.length; i++)
    result[i] = (byte) ((byte) ((byte) 0xf0 & ((getByte(text.charAt(2 * i))) << 4))
            | getByte(text.charAt(2 * i + 1)));
return result;
byte[]fromHex(String[] data)
from Hex
StringBuilder sb = new StringBuilder();
for (String s : data) {
    sb.append(s);
return fromHex(sb.toString());
intfromHex2B(String src)
from Hex B
byte[] b = fromHex(src);
int position = 0;
int i = (b[position++] & 0xff);
i |= (b[position++] & 0xff) << 8;
return i;
longfromHex8B(String src)
from Hex B
byte[] b = fromHex(src);
int position = 0;
long l = (b[position++] & 0xff);
l |= (long) (b[position++] & 0xff) << 8;
l |= (long) (b[position++] & 0xff) << 16;
l |= (long) (b[position++] & 0xff) << 24;
l |= (long) (b[position++] & 0xff) << 32;
l |= (long) (b[position++] & 0xff) << 40;
...
byte[]fromHexa(String s)
from Hexa
byte[] ret = new byte[s.length() / 2];
for (int i = 0; i < ret.length; i++) {
    ret[i] = (byte) Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16);
return ret;