Calculation Method of number-to-digit conversion for ID card numbers

Source: Internet
Author: User
The meaning of the number of digits in the ID card!
(1) The first 1 and 2 digits indicate the code of the province;
(2) The Code of the city where the user is located is represented by 3rd and 4 digits;
(3) 5th and 6 digits: the code of the Jinniu District and County;
(4) 7th ~ 14 digits indicate the year, month, and day of birth;
(5) 15th and 16 digits indicate the code of the local police station;
(6) 17th digits indicate gender. an odd number indicates male and an even number indicates female;
(7) The 18th digit is the verification code:

According to the national standard of GB11643-1999 "citizen ID card number", the civil ID card number consists of 18 digits: the first 6 digits are the administrative district code, and the first 6 digits to 14 digits are the birth date code, the 15th-17 bits are sequential codes, and the 18th bits are verification codes.
The 18th-digit number is a verification code. It is used to check the correctness of the ID card number. It is generated randomly by a computer. Therefore, the number of male is no longer a singular number, and the number of female is a double number.
A citizenship number is a combination of features and consists of a 17-digit ontology code and a 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.
2. Address Code (first six digits)
Indicates the Administrative Code of the county (city, flag, district) where the resident account of the encoding object is located, which is executed according to GB/t2260.
3. Date of Birth (seventh to fourteen digits)
Indicates the year, month, and day when the encoding object is born. The code is executed according to GB/t7408, and there is no separator between the year, month, and day codes.
4. sequence code (15th-17 digits)
Indicates the sequence number of the person born on the same year, the same month, and the same day within the region specified by the same address code. The odd number of the sequence code is allocated to men, and the even number is allocated to women.
5. Verification Code (18th digits)
(1) 17-digit ontology weighted sum formula
S = sum (ai * WI), I = 0,..., 16, first sum the right of the first 17 digits
AI: indicates the number of ID card numbers at location I.
Wi: indicates the weighting factor at position I.
Wi: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
(2) Computing Model
Y = Mod (S, 11)
(3) obtain the corresponding verification code through the modulo
Y: 0 1 2 3 4 5 6 7 8 9 10
Verification Code: 1 0x9 8 7 6 5 4 3 2

Bytes --------------------------------------------------------------------------------------------------------

/**
* @ Author Kevin. Wang
* @ 2007-1-24
*/
Public class generate18idfrom15id {
// Indicates the weighting factor at position I.
Private Static final int [] Wi = {, 2 };
Private Static final char [] Y = {'1', '0', 'x', '9', '8', '7', '6 ', '5', '4', '3', '2 '};
// XXXX user's year of birth
Private Static string birthdayyear = "1981 ";

Public static void main (string [] ARGs ){
String old15id = "123456789123456 ";

String prefix = old15id. substring (0, 6 );
String Postfix = old15id. substring (6, 15 );

String new18id = new stringbuffer (). append (prefix). append (birthdayyear. substring (0, 2). append (postfix). tostring ();

Int Total = 0;
For (INT I = 0; I <wi. length; I ++ ){
Int temp = integer. parseint (string. valueof (new18id. charat (I )));
Total + = temp * WI [I];
}
Int lastnum = Total % 11;


New18id = new18id + Y [lastnum];

System. Out. println ("prefix =" + prefix );
System. Out. println ("Postfix =" + postfix );
System. Out. println ("new18id =" + new18id );
}
}

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.