Here you can find the source of toGuidBytes(UUID theUuid)
public static byte[] toGuidBytes(UUID theUuid)
//package com.java2s; // License: https://servicestack.net/bsd-license.txt import java.nio.ByteBuffer; import java.util.UUID; public class Main { public static byte[] toGuidBytes(UUID theUuid) { ByteBuffer first8 = ByteBuffer.allocate(8); first8.putLong(theUuid.getMostSignificantBits()); first8.rewind();/*from w w w . j a va 2s .c om*/ byte[] first4 = new byte[4]; first8.get(first4); reverse(first4); byte[] second2 = new byte[2]; first8.get(second2); reverse(second2); byte[] third2 = new byte[2]; first8.get(third2); reverse(third2); ByteBuffer converted16 = ByteBuffer.allocate(16).put(first4).put(second2).put(third2); ByteBuffer last8 = ByteBuffer.allocate(8); last8.putLong(theUuid.getLeastSignificantBits()); last8.rewind(); converted16.put(last8); return converted16.array(); } public static void reverse(byte[] bytes) { if (bytes == null) return; int i = 0; int j = bytes.length - 1; byte hold; while (j > i) { hold = bytes[j]; bytes[j] = bytes[i]; bytes[i] = hold; j--; i++; } } }