Java tutorial
//package com.java2s; //License from project: LGPL import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.UUID; public class Main { public static final String BASE_UUID_START = "0000"; public static final String BASE_UUID_END = "-0000-1000-8000-00805f9b34fb"; public static String bytesToUuid(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(ByteOrder.LITTLE_ENDIAN); long lsb = bb.getLong(); long msb = bb.getLong(); UUID uuid = new UUID(msb, lsb); return uuidToString(uuid); } public static String uuidToString(UUID uuid) { String uuidString = uuid.toString(); if (uuidString.startsWith(BASE_UUID_START) && uuidString.endsWith(BASE_UUID_END)) { return uuidString.substring(4, 8); } return uuidString; } }