The GUID is converted to a 16-bit string or a 19-bit unique string, with 19 guidbits.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.