Conversion procedures for new and old ID card numbers

Source: Internet
Author: User

Use the New and Old ID card number conversion program compiled by STL to automatically identify and convert the input ID card number type. The main body of the Code is the following two functions. For how to convert the ID card number, see the appendix below: convert a 15-digit ID card number to an 18-digit number

 

String conver15to18 (const string & str15bid)
{
Static char szjiaoyan [11] = {'1', '0', 'x', '9', '8', '7', '6', '5 ', '4', '3', '2 '};
Static int nweight [] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };

String str18bid = str15bid. substr (0, 6 );
String stryear;
// Char * pyear = stryear. c_str ();
Int nyear = atoi (str15bid. substr (6, 2). c_str ());
If (nyear> 4) // now is 2004
Stryear = "19 ";
Else
Stryear = "20 ";
Str18bid + = stryear;
Str18bid + = str15bid. substr (6, 9 );
// Calculate the verification of the last digit
Int ntotal = 0;
Char szlastjiao [2];
For (INT I = 0; I <str18bid. Size (); I ++)
{
Ntotal + = (INT (str18bid [I]-'0') * nweight [I]);
}
Ntotal = ntotal % 11;
Szlastjiao [0] = szjiaoyan [ntotal];
Szlastjiao [1] = 0;
String strjcode = szlastjiao;
Str18bid + = strjcode;

Return str18bid;
}

 

Convert the 18-digit ID card number into a 15-digit number

 

String conver18to15 (const string & str18bid)
{
String str15bid = str18bid. substr (0, 6 );
Str15bid + = str18bid. substr (8, 9 );

Return str15bid;
}

 

Download: http://blog.csdn.net/images/blog_csdn_net/orbit/IDCardNumber.zip

Appendix: according to the provisions on citizenship numbers in the National Standard of the People's Republic of China (GB 11643-1999), a citizenship number is a combination of features and consists of a 17-digit ontology code and a digital verification code. The six-digit address code, eight-digit birth date code, three-digit sequence code, and one-digit verification code are arranged from left to right. The address code indicates the Administrative Code of the county (city, flag, district) where the resident account of the encoding object is located. The birthdate code indicates the year, month, and day of the encoding object. The year is represented by four digits, and there is no separator between the year, month, and day. The sequence number indicates the sequence number of persons born in the same year, month, or day within the region specified by the same address code. The odd number of the sequence code is assigned to men, and the even number is assigned to women. The verification code is calculated based on the first 17-digit code according to the ISO 7064: 1983.mod 11-2 verification code. The following is an example of this calculation method. The 15-digit ID card code first expands the birth year to four digits. Simply, it adds 19 digits, but this is not used by people born in 1900 (there are not many such life stars) the subject code of a male citizenship number is 34052419800101001. First, calculated by formula (1): Σ (AI × WI) (mod 11 ).......................................... (1) formula (1): I ---- indicates the serial number of the number character from the position that includes the verification code to the left; AI ---- indicates the value of the number character at the position I; wi ---- indicates the weighting factor at position I. The value is calculated based on the formula Wi = 2 (n-1) (mod 11. I 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 AI 3 4 4 0 5 2 1 9 8 0 0 1 0 1 0 1 A1 wi 7 9 10 5 8 4 2 1 6 3 7 9 10 5 4 2 1 AI x wi 21 36 0 25 16 16 2 9 48 0 0 9 0 5 0 0 2 A1 according to the formula (1) computing: Σ (AI × WI) = (21 + 36 + 0 + 25 + 16 + 16 + 2 + 9 + 48 + 0 + 0 + 9 + 0 + 5 + 0 + 0 + 2) = 189 189 12711 = 17 + 2/11 Σ (AI × WI) (mod 11) = 2. Then, based on the calculation results, find the corresponding verification code from the following table, X indicates that the calculation result is 10: Σ (AI × WI) (mod 11) 0 1 2 3 4 5 6 7 8 9 10 Verification Code character value AI 1 0x9 8 7 6 5 4 3 2 According to the preceding table, the verification code of the calculation result 2 is found to be 34052419800101001x.

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.