Generate 16-bit string (No Duplicates)

Source: Internet
Author: User

Using System;

Namespace Getsysid
{
<summary>
Summary description of the SYSID.
</summary>
public class Getsysid
{
Public Getsysid ()
{
//
TODO: Add constructor logic here
//
}
public string Sysid ()
{
String Sysid,lc,lc1,ss;

String year,day,hour,minute,sec,msec;
Year = System.DateTime.Now.Year.ToString ();
Day = System.DateTime.Now.DayOfYear.ToString ();
hour = System.DateTime.Now.Hour.ToString ();
minute = DateTime.Now.Minute.ToString ();
SEC = DateTime.Now.Second.ToString ();
msec = DateTime.Now.Millisecond.ToString ();

if (year). Length = = 4)
{
Year = year. Substring (2,2);
}

LC1 = "";
LC1 = LC1 + changstr (true,year, "0", 2);
LC1 = LC1 + changstr (true,day, "0", 3);
LC1 = LC1 + changstr (true,hour, "0", 2);
LC1 = LC1 + changstr (true,sec, "0", 2);

Long T;
t = Convert.toint64 (LC1);

LC1 = "";
LC1 = Inttohex (t,8);

SS = Changstr (True,sec, "0", 2);
t = Convert.toint64 (ss);
LC1 = LC1 + Inttohex (t,2);
LC1 = LC1 + Inttohex (Convert.toint64 (msec), 3);

64 in-system
SS = System.Guid.NewGuid (). ToString ();
LC = ss. Substring (0,8);
LC = CHECKID (LC);

LC1 = LC1 + changstr (TRUE,LC, "0", 8);
SS = "";

SS = LC1. Substring (1,8);
Sysid = HexTo36 (ss,6);
Ss= LC1. Substring (8,13);
Sysid = Sysid + HexTo36 (ss,10);

return sysid;
}


Convert to hexadecimal data
private string Inttohex (long Num,int len)
{
String Lchexstr,strhex;
Lchexstr = "0123456789ABCDEF";
int lmod,len1;
Lmod = 0;
Strhex = "";

while (num > 0)
{
Lmod = (int) (num% 16);
num = NUM/16;
Strhex = Lchexstr.substring (lmod, 1) + Strhex;
}

Len1 = Strhex.length;
if (Len1 < len)
Strhex = Changstr (True,strhex, "0", Len);
return strhex;
}

Change the string to a specified length
private string Changstr (bool bisf,string strhex,string substr,int @len)
{
int len1;
Len1 = Len-strhex.length;
for (int i = 0; i < len1; i++)
{
if (BISF = = True)
Strhex = SubStr + Strhex;
Else
Strhex = Strhex + subStr;
}
return strhex;
}

Check string
private string Checkid (String str)
{
String outstr;
Char charstr;
int Len;
outstr = "";

str = str. ToUpper ();
Len = str. Length;

for (int i =0; i < Len; i++)
{
Charstr = Str[i];
if ((((int) charstr >=) && ((int) charstr <= 59) | | (((int) charstr >=) && ((int) charstr <= 70))
{
outstr = outstr + charstr;
}
Else
outstr = outstr + inttohex ((int) charstr,0);
}
if (Outstr.length > 8)
outstr = outstr.substring (0,8);
return outstr;
}

Convert to 36 binary
private string HexTo36 (string Strhex,int len)
{
String Str62,lc62str;
Lc62str = "0123456789" + "abcdefghijklmnopqrstuvwxyz";
Str62 = "";
int lmod = 0;
Long num1 = 0;

Convert to Decimal
Long Lnshex = 1;
Strhex = Strhex.toupper ();
int len1;
Len1 = Strhex.length;
while (Len1 > 0)
{
Char SS;
SS = strhex[(len1-1)];
NUM1 = Num1 + (Lc62str.indexof (ss)) * LNSHEX;
if (len1 = 1)
Lnshex = 16;
Else
Lnshex = Lnshex * 16;
Len1--;
LISTBOX1.ITEMS.ADD (NUM1. ToString ());
}

MessageBox.Show (NUM1. ToString ());
Convert to 36 binary
Str62 = "";
while (Num1 > 0)
{
Lmod = (int) (num1% 36);
NUM1 = NUM1/36;
Str62 = Lc62str.substring (lmod, 1) + str62;
}
Len1 = str62. Length;

if (Len1 < len)
{
Str62 = Changstr (true,str62, "0", Len);
}
return str62;
}
}
}

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.