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

StringtoHex(long i, int r0, boolean r1)
Converts a number to a hex value
String h = Long.toHexString(i).toUpperCase();
while (h.length() < r0 && r1) {
    h = 0 + h;
return (r1 ? "0x" : "") + h;
StringtoHex(long l, int length)
Converts the given long to a hexadecimal string of length characters.
return String.format("%" + length + "s", Long.toHexString(l)).replace(' ', '0');
StringtoHex(Long value, int charCount)
Return a number as hex value with specified char count.
String s = Long.toHexString(value).toUpperCase();
while (s.length() > charCount) {
    s = s.substring(1);
if (s.length() < charCount) {
    int diff = charCount - s.length();
    for (int i = 0; i < diff; i++)
        s = "0" + s;
...
StringtoHex(long value, int length)
Converts a long value to an HEX string.
return String.format("%0" + length + "X", value);
StringtoHex(String color)
Sends a colour to a hex
if (color == null) {
    return "00";
Integer N;
N = Integer.parseInt(color);
if (N == 0) {
    return "00";
N = Math.max(0, N);
N = Math.min(N, 255);
N = Math.round(N);
char s = chars.charAt((N - N % 16) / 16);
char s1 = chars.charAt(N % 16);
return "" + Character.toString(s) + Character.toString(s1);
StringtoHex(String in, boolean javaStyle)
to Hex
StringBuilder result = new StringBuilder();
for (int i = 0; i < in.length(); ++i) {
    result.append(toHex(in.charAt(i), javaStyle));
return result.toString();
StringtoHEX(String ostr)
to HEX
StringBuffer rst = new StringBuffer();
for (int i = 0; i < ostr.length(); i++) {
    rst.append(Integer.toHexString(ostr.charAt(i)).toUpperCase());
return rst.toString();
StringtoHex(String source)
Outputs Unicode codepoint representation.
StringBuilder sb = new StringBuilder();
for (char ch : source.toCharArray()) {
    sb.append("U+").append(padLeft(ch, 4));
return sb.toString();
StringtoHex(String str)
to Hex
StringBuffer buff = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
    if (Character.isLetter(str.charAt(i))
            || Character.isDigit(str.charAt(i))) {
        buff.append(str.charAt(i));
    } else {
        buff.append("\\u00");
        buff.append(Integer.toHexString(str.charAt(i)));
...
StringtoHex(String string)
to Hex
char[] chars = string.toCharArray();
StringBuilder buf = new StringBuilder();
for (char c : chars) {
    buf.append(Integer.toHexString(c).toUpperCase());
return buf.toString();