Java Utililty Methods Long to Hex

List of utility methods to do Long to Hex

Description

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

Method

StringLong2HexString(long h)
Long Hex String
try {
    return Long.toHexString(h);
} catch (Exception e) {
    e.printStackTrace();
return "0";
Stringlong2hexString(long x)
longhex String
String s = "";
for (int ii = 0; ii < 16; ii++) {
    s = hex_digit[(int) ((x & (15L << (ii * 4))) >>> (ii * 4))] + s;
return s;
voidlong2HexString(StringBuilder buf, long value)
This method avoids the use on Long.toHexString, since this class may be used during the boot-phase when the Long class in not yet initialized.
int rem = (int) (value & 0x0FL);
long q = value >>> 4;
if (q != 0) {
    long2HexString(buf, q);
if (rem < 10) {
    buf.append((char) ('0' + rem));
} else {
...
StringlongToHex(long a)
long To Hex
byte[] b = new byte[8];
longToBytes(a, b, 0);
return bytesToHex(b);
StringlongToHex(long l)
Convert a long to a hex representation.
return Long.toHexString(l);
StringlongToHex(long l, int length)
long To Hex
String temp = Long.toHexString(l);
while (temp.length() < length * 2) {
    temp = "0" + temp;
return temp;
StringlongToHex(long num)
A quick method to convert num to a hexadecimal number.
return (num < 16L) ? "0" + Long.toString(num) : Long.toString(num, 16);
StringlongToHex(long val, char delim)
long To Hex
byte[] bytes = new byte[8];
for (int i = 7; i >= 0; i -= 1) {
    bytes[7 - i] = (byte) ((val >>> (i * 8)) & 0xFF);
return bytesToHex(bytes, delim);
StringlongToHexBytes(final long v)
Returns a string of spaced hex bytes in Big-Endian order.
final long mask = 0XFFL;
final StringBuilder sb = new StringBuilder();
for (int i = 8; i-- > 0;) {
    final String s = Long.toHexString((v >>> i * 8) & mask);
    sb.append(zeroPad(s, 2)).append(" ");
return sb.toString();
byte[]longToHexBytes(long i)
long To Hex Bytes
byte[] bytes = new byte[16];
oneByteToHexBytes((byte) ((i >>> 56) & 0xff), bytes, 0);
oneByteToHexBytes((byte) ((i >>> 48) & 0xff), bytes, 2);
oneByteToHexBytes((byte) ((i >>> 40) & 0xff), bytes, 4);
oneByteToHexBytes((byte) ((i >>> 32) & 0xff), bytes, 6);
oneByteToHexBytes((byte) ((i >>> 24) & 0xff), bytes, 8);
oneByteToHexBytes((byte) ((i >>> 16) & 0xff), bytes, 10);
oneByteToHexBytes((byte) ((i >>> 8) & 0xff), bytes, 12);
...