UUID As byte array. - Android java.util

Android examples for java.util:UUID

Description

UUID As byte array.

Demo Code


//package com.java2s;

public class Main {
    /**//  w w w .j  a va2  s  .  c o  m
     * As byte array.
     * 
     * @param uuid
     * @return byte[16]
     */
    public static byte[] asByteArray(java.util.UUID uuid) {
        long msb = uuid.getMostSignificantBits();
        long lsb = uuid.getLeastSignificantBits();
        byte[] buffer = new byte[16];
        for (int i = 0; i < 8; i++) {
            buffer[i] = (byte) (msb >>> 8 * (7 - i));
        }
        for (int i = 8; i < 16; i++) {
            buffer[i] = (byte) (lsb >>> 8 * (7 - i));
        }
        return buffer;
    }
}

Related Tutorials