The GUID is converted to a 16-bit string or a 19-bit unique string, with 19 guidbits.
Sort out several common methods to convert a GUID to a 16-bit string or a 19-bit unique string:
/// <Summary> /// obtain a 16-bit unique string based on the GUID /// Author: fu Yifang // </summary> /// <param name = \ "guid \"> </param> /// <returns> </returns> public static string GuidTo16String () {long I = 1; foreach (byte B in Guid. newGuid (). toByteArray () I * = (int) B + 1); return string. format ("{0: x}", I-DateTime. now. ticks) ;}/// <summary> /// obtain a 19-bit unique sequence of numbers based on the GUID /// Author: payer // </summary> /// <returns> </returns> public static long GuidToLongID () {byte [] buffer = Guid. newGuid (). toByteArray (); return BitConverter. toInt64 (buffer, 0) ;}/// <summary> /// generate a 22-bit unique number for concurrent use /// Author: payer // </summary> /// <returns> </returns> public static string GenerateUniqueID () {System. threading. thread. sleep (1); // ensure that the unique Random d = new Random (BitConverter. toInt32 (Guid. newGuid (). toByteArray (), 0); string strUnique = DateTime. now. toString ("yyyyMMddHHmmssffff") + d. next (1000,999 9); return strUnique;} /// <summary> // generate a 22-bit unique number for concurrent use // Author: payer // </summary> /// <returns> </returns> public static string GenerateUniqueID () {System. threading. thread. sleep (1); // ensure that the unique Random d = new Random (BitConverter. toInt32 (Guid. newGuid (). toByteArray (), 0); string strUnique = DateTime. now. toString ("yyyyMMddHHmmssffff") + d. next (1000,999 9); return strUnique ;}
I hope the above information will be helpful to beginners. Thank you!
More follow Fu Yi Fang technology blog: http://blog.csdn.net/fuyifang
Or scan the QR code on your mobile phone to view more blog posts:
Copyright statement: This article is the original author of the blog, not allowed by the blog can not be reproduced, more attention to pay the technical blog: http://blog.csdn.net/fuyifang