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(long i)
to Hex String
return toUnsignedString(i, 4);
StringtoHexString(long l)
J2ME/J9 compatibility instead of Long.toHexString Copied from bluecove: http://www.bluecove.org/bluecove/apidocs/com/intel/bluetooth/Utils.html
StringBuffer buf = new StringBuffer();
String lo = Integer.toHexString((int) l);
if (l > 0xffffffffl) {
    String hi = Integer.toHexString((int) (l >> 32));
    buf.append(hi);
    for (int i = lo.length(); i < 8; i++) {
        buf.append('0');
buf.append(lo);
return buf.toString();
StringtoHexString(long l)
Converts long to hexadecimal string.
return Long.toString(l, 16);
StringtoHexString(long l)
to Hex String
return String.format("%x", l);
StringtoHexString(long l)
Convert a long to it's hex representation.
String initial;
StringBuffer sb;
initial = Long.toHexString(l);
if (initial.length() == 16)
    return initial;
sb = new StringBuffer(16);
sb.append(initial);
while (sb.length() < 16)
...
StringtoHexString(long value, int digits)
to Hex String
String ret = toHexString(value);
int add = digits - getStringLength(ret);
for (int i = 0; i < add; i++) {
    ret = "0" + ret;
return ret;
StringtoHexString(long value, int digits)
Returns a hexadecimal string representing the passed value, padded as necessary to the specified number of digits.
StringBuilder sb = new StringBuilder(digits);
while (digits > 0) {
    int nibble = (int) (value & 0xF);
    sb.insert(0, "0123456789ABCDEF".charAt(nibble));
    value >>= 4;
    digits--;
return sb.toString();
...
StringToHexString(long[] data)
To Hex String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length; i++) {
    sb.append(PadLeft(Long.toHexString(data[i]), 16));
return sb.toString();
StringtoHexString(String data)
Convert string to hex string.
char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
byte[] byteData = data.getBytes();
int length = byteData.length;
char[] charBuffer = new char[length * 2];
int next;
for (int byteCnt = 0, charCnt = 0; byteCnt < length;) {
    next = byteData[byteCnt++];
    charBuffer[charCnt++] = HEX_CHARS[(next >>> 4) & 0x0F];
...
StringtoHexString(String input)
to Hex String
StringBuffer sb = new StringBuffer();
byte[] bytes = input.getBytes();
for (int i = 0; i < bytes.length; i++) {
    String hex = Integer.toHexString(bytes[i]);
    if (hex.length() == 1) {
        sb.append("0");
    } else if (hex.length() > 2) {
        hex = hex.substring(hex.length() - 2, hex.length());
...