Java Utililty Methods Hex Calculate

List of utility methods to do Hex Calculate

Description

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

Method

StringtoHexString(String s)
to Hex String
String str = "";
for (int i = 0; i < s.length(); i++) {
    int ch = s.charAt(i);
    String s4 = Integer.toHexString(ch);
    str = str + s4;
return str;
StringtoHexString(String s)
to Hex String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
    char ch = s.charAt(i);
    if (i > 0) {
        sb.append(' ');
    if (ch < 128) {
        sb.append(ch);
...
StringtoHexString(String s)
to Hex String
byte[] baKeyword = new byte[s.length() / 2];
for (int i = 0; i < baKeyword.length; i++) {
    try {
        baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
    } catch (Exception e) {
        e.printStackTrace();
try {
    s = new String(baKeyword, "utf-8");
} catch (Exception e1) {
    e1.printStackTrace();
return s;
String[]toHexString(String str)
to Hex String
char[] chars = str.toCharArray();
String[] result = new String[chars.length];
for (int i = 0; i < chars.length; i++) {
    result[i] = Integer.toHexString((int) chars[i]);
return result;
StringtoHexString(String str)
to Hex String
int hashCode = str.hashCode();
return toHexString(hashCode);
voidtoHexString(StringBuffer buffer, byte[] bytes, int numBytes)
to Hex String
buffer.append('[');
if (bytes != null) {
    for (int i = 0; i < numBytes; i++) {
        String chars = Integer.toHexString(bytes[i] & 0xFF);
        if (chars.length() == 1) {
            buffer.append('0');
        buffer.append(chars);
...
StringtoHexString0x(byte[] byteArray)
to Hex Stringx
if (byteArray == null) {
    return null;
return "0x" + toHexString(byteArray);
StringtoHexString2(int i)
to Hex String
String zeros = "00000000000";
String hex = Integer.toHexString(i);
int len = hex.length();
if (len < 2)
    return zeros.substring(0, 2 - len) + hex;
else
    return hex.substring(0, 2);
StringtoHexString3(byte aByte)
to Hex String
String str = Integer.toHexString(byteToInt(aByte));
String s = str.length() == 1 ? "0x0" + str : "0x" + str;
return s;
StringtoHexStringBE(char[] array)
to Hex String BE
return toHexStringBE(array, 0, array.length);