C # applet 15-bit ext. 18-bit ID Code _c# tutorial

Source: Internet
Author: User
Tags readline

Now we are using the 18 ID card number, and the previous 15 ID card number, and how to convert the 15 ID card number to the 18-digit ID number to 18 ID card number?

1, first, in the 15 ID card after the 6th plus "19" into 17, that is, the year of birth plus 19, such as the original 92 years to become 1992

2, then, is the last calculation, the method is as follows:

1 1 of the 17-digit ID number, each bit multiplied by the corresponding coefficient, 17-bit coefficient is {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}

2) The sum of 17 numbers is calculated by adding (1) to the TEMP


3 The temp divided by 11, temp%=11;

4) After the result of the remainder as the mantissa array endnum[] subscript, find out the value of endnum[temp], and then add endnum[temp] to the 17 ID card after the 18-bit,

Mantissa array endnum[]={' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '};

Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;

Namespace Idcard
{
Class Program
{
<summary>
Main function
</summary>
<param name= "args" ></param>
static void Main (string[] args)
{
Console.Write ("Please enter 15 ID card number:");
String Oldid=console.readline ()//Enter 15 ID number
String NewId =idcardtranslation (oldid);//new ID number
Console.WriteLine ("18 New ID number is: {0}", newId);/output
Console.ReadLine ();
}
<summary>
15 ID Card number to 18-digit ID number
</summary>
<param name= "Oldcard" >15 position ID number </param>
&LT;RETURNS&GT;18 ID Number </returns>
private static string Idcardtranslation (String oldcard)
{
int[] coefficient = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};//17-bit ID card number per digit factor
Char[] Endnum = {' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '};//ID card last array
if (oldcard.length = = 15)//To determine whether it is 15 bits
{
String NewID = Oldcard.insert (6, "19");//Add 19 to the 6th digit of the 15-bit ID number and become 17-bit
int s = 0;
for (int i = 0; i < i++)//17-bit number every bit is multiplied by the corresponding coefficient
{
int temp = Convert.ToInt32 (Newid[i]) * Coefficient[i];
s + + temp;//multiply coefficient after sum
}
S%= 11;//divided by 11.
NewID + = Endnum[s]. ToString ();//17 digit number plus remainder represents the subscript in the mantissa array endnum characters
Return newid;//new ID number
}
Else
{
Return "";
}
}
}
}

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.