Fan.Sys.Uuid.Factory.toLong C# (CSharp) Method

toLong() private method

private toLong ( byte bytes ) : long
bytes byte
return long
            private long toLong(byte[] bytes)
            {
                // if bytes less then 6 pad with random
                if (bytes.Length < 6)
                {
                  byte[] temp = new byte[6];
                  Array.Copy(bytes, 0, temp, 0, bytes.Length);
                  for (int i=bytes.Length; i<temp.Length; ++i)
                temp[i] = (byte)FanInt.random();
                  bytes = temp;
                }

                // mask bytes into 6 byte long
                long x = ((bytes[0] & 0xFFL) << 40) |
                 ((bytes[1] & 0xFFL) << 32) |
                 ((bytes[2] & 0xFFL) << 24) |
                 ((bytes[3] & 0xFFL) << 16) |
                 ((bytes[4] & 0xFFL) <<  8) |
                 ((bytes[5] & 0xFFL) <<  0);

                // if we have more then six bytes mask against primary six bytes
                for (int i=6; i<bytes.Length; ++i)
                  x ^= (bytes[i] & 0xFFL) << (((i - 6) % 6) * 8);

                return x;
            }