GUID to ByteArray

Posted by DutrowLLC on Stack Overflow See other posts from Stack Overflow or by DutrowLLC
Published on 2010-06-06T04:11:43Z Indexed on 2010/06/06 4:12 UTC
Read the original article Hit count: 385

Filed under:
|
|
|
|

I just wrote this code to turn a GUID into a byte array. Can anyone shoot any holes in it or suggest something better?

 public static byte[] getGuidAsByteArray(){

UUID uuid = UUID.randomUUID(); long longOne = uuid.getMostSignificantBits(); long longTwo = uuid.getLeastSignificantBits();

    return new byte[] {
      (byte)(longOne >>> 56),
      (byte)(longOne >>> 48),
            (byte)(longOne >>> 40),
            (byte)(longOne >>> 32),   
      (byte)(longOne >>> 24),
            (byte)(longOne >>> 16),
            (byte)(longOne >>> 8),
            (byte) longOne,
      (byte)(longTwo >>> 56),
      (byte)(longTwo >>> 48),
            (byte)(longTwo >>> 40),
            (byte)(longTwo >>> 32),   
      (byte)(longTwo >>> 24),
            (byte)(longTwo >>> 16),
            (byte)(longTwo >>> 8),
            (byte) longTwo
            };

}

© Stack Overflow or respective owner

Related posts about java

Related posts about convert