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(int n, Boolean bigEndian)
Outputs the hex value of a int, allowing the developer to specify the endinaness in the process.
String s = "";
if (bigEndian) {
    for (int i = 0; i < 4; i++) {
        s += hexChars.charAt((n >> ((3 - i) * 8 + 4)) & 0xF) + hexChars.charAt((n >> ((3 - i) * 8)) & 0xF);
} else {
    for (int x = 0; x < 4; x++) {
        s += hexChars.charAt((n >> (x * 8 + 4)) & 0xF) + hexChars.charAt((n >> (x * 8)) & 0xF);
...
StringtoHex(int n, int bytes)
Converts the given number into a hex string
if ((bytes < 1) || (bytes > 4)) {
    bytes = 4;
StringBuffer sb = new StringBuffer();
for (int i = (bytes - 1); i >= 0; i--) {
    sb.append(hexDigit[(n >> ((i * 8) + 4)) & 0x0F]);
    sb.append(hexDigit[(n >> (i * 8)) & 0x0F]);
return sb.toString();
StringtoHex(int n, int s)
to Hex
String str = "0000000000000000" + Integer.toHexString(n);
return str.substring(str.length() - s);
chartoHex(int nibble)
to Hex
return hexDigit[(nibble & 0xF)];
StringtoHex(int num)
to Hex
num = num & 0xff;
final String hex = Integer.toHexString(num);
return hex.length() == 1 ? "0" + hex : hex;
chartoHex(int nybble)
to Hex
if (nybble < 0 || nybble > 15) {
    throw new IllegalArgumentException();
return "0123456789ABCDEF".toLowerCase().charAt(nybble);
StringtoHex(int r, int g, int b)
to Hex
return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
inttoHex(int r, int g, int b)
to Hex
int hex = 0;
hex = hex | ((r) << 16);
hex = hex | ((g) << 8);
hex = hex | ((b));
return hex;
StringtoHex(int r, int g, int b)
Returns a web browser-friendly HEX value representing the colour in the default sRGB ColorModel.
if ((r >= 0) && (r <= 255) && (g >= 0) && (g <= 255) && (b >= 0) && (b <= 255)) {
    return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
} else {
    return null;
StringtoHex(int v)
to Hex
v = Math.min(Math.max(v, 0), 255);
return String.valueOf("0123456789abcdef".charAt(((v - v % 16) / 16))) + 
        String.valueOf("0123456789abcdef".charAt(v % 16));