身份证号校验公式
原理:
身份證號(hào)的最后一位是根據(jù)前 17 位數(shù)字計(jì)算出來的,具有唯一性。
計(jì)算方式:
將身份證號(hào)的 { [第 1 個(gè)數(shù)字 (2^17/11) 的余數(shù)] + [第 2 個(gè)數(shù)字 (2^16/11)的余數(shù)] + …+ [第 17 個(gè)數(shù)字 * (2^1/11)的余數(shù)] } ,將所得的數(shù)除以 11 后,得到的余數(shù)按照
| 0 | 1 |
| 1 | 0 |
| 2 | X |
| 3 | 9 |
| 4 | 8 |
| 5 | 7 |
| 6 | 6 |
| 7 | 5 |
| 8 | 4 |
| 9 | 3 |
| 10 | 2 |
依次對(duì)應(yīng)。最后的結(jié)果就是第 18 位身份證號(hào)校驗(yàn)位。
公式代碼:
Excel公式
=LOOKUP(MOD(MID(B3,1,1)*MOD(2^17,11)+MID(B3,2,1)*MOD(2^16,11)+MID(B3,3,1)*MOD(2^15,11)+MID(B3,4,1)*MOD(2^14,11)+MID(B3,5,1)*MOD(2^13,11)+MID(B3,6,1)*MOD(2^12,11)+MID(B3,7,1)*MOD(2^11,11)+MID(B3,8,1)*MOD(2^10,11)+MID(B3,9,1)*MOD(2^9,11)+MID(B3,10,1)*MOD(2^8,11)+MID(B3,11,1)*MOD(2^7,11)+MID(B3,12,1)*MOD(2^6,11)+MID(B3,13,1)*MOD(2^5,11)+MID(B3,14,1)*MOD(2^4,11)+MID(B3,15,1)*MOD(2^3,11)+MID(B3,16,1)*MOD(2^2,11)+MID(B3,17,1)*MOD(2^1,11),11),{0;1;2;3;4;5;6;7;8;9;10},{1;0;"X";9;8;7;6;5;4;3;2})
C語言代碼
#include<stdio.h> #include<stdlib.h> #include<math.h>int reIdNum(char id[]){char check = '1';int i = 16, sum = 0, result;for(i = 16; i >= 0; i--){sum += ( (id[16-i] - '0') * (int(pow(2,(i+1))) % 11) );}switch (sum % 11){case 0 : check = '1'; break;case 1 : check = '2'; break;case 2 : check = 'X'; break;case 3 : check = '9'; break;case 4 : check = '8'; break;case 5 : check = '7'; break;case 6 : check = '6'; break;case 7 : check = '5'; break;case 8 : check = '4'; break;case 9 : check = '3'; break;case 10 : check = '2'; break;}if(id[17] == check){result = 1;}else{result = 0;}return (result); }int main(){char id[19];puts("Please enter IdNumber:");scanf("%s", id);if(reIdNum(id)){puts("The IdNumber is ture.");}else{puts("The IdNumber is false.");}system("pause");return (0); }總結(jié)
- 上一篇: 电脑W7系统怎样安装鸿蒙系统,家用电脑升
- 下一篇: 字体格式转换器