Here you can find the source of longToHexBytes(long i)
public static byte[] longToHexBytes(long i)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] longToHexBytes(long i) { 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); oneByteToHexBytes((byte) (i & 0xff), bytes, 14); return bytes; }//from w w w . j a v a2s .c o m public static byte[] longToHexBytes(long i, byte[] bytes) { 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); oneByteToHexBytes((byte) (i & 0xff), bytes, 14); return bytes; } public static byte[] longToHexBytes(long i, byte[] bytes, int startIdx) { oneByteToHexBytes((byte) ((i >>> 56) & 0xff), bytes, startIdx); oneByteToHexBytes((byte) ((i >>> 48) & 0xff), bytes, startIdx + 2); oneByteToHexBytes((byte) ((i >>> 40) & 0xff), bytes, startIdx + 4); oneByteToHexBytes((byte) ((i >>> 32) & 0xff), bytes, startIdx + 6); oneByteToHexBytes((byte) ((i >>> 24) & 0xff), bytes, startIdx + 8); oneByteToHexBytes((byte) ((i >>> 16) & 0xff), bytes, startIdx + 10); oneByteToHexBytes((byte) ((i >>> 8) & 0xff), bytes, startIdx + 12); oneByteToHexBytes((byte) (i & 0xff), bytes, startIdx + 14); return bytes; } private static byte[] oneByteToHexBytes(byte b, byte[] hexBytes, int startIdx) { byte high = (byte) ((b & 0xf0) >>> 4); if (high <= 9) high += '0'; else high += ('A' - 10); hexBytes[startIdx] = high; byte low = (byte) (b & 0x0f); if (low <= 9) low += '0'; else low += ('A' - 10); hexBytes[startIdx + 1] = low; return hexBytes; } }