zoukankan      html  css  js  c++  java
  • 用C#实现由15位身份证号升级到18位的算法!

     1using System;
     2using System.Collections;
     3
     4public class MyClass
     5{
     6    public static void Main()
     7    {
     8        Console.WriteLine(per15To18("429005811009091"));
     9        RL();
    10    }

    11    
    12    public static string per15To18(string perIDSrc) 
    13  
    14   int iS = 0
    15 
    16   //加权因子常数 
    17   int[] iW=new int[]{7910584216379105842};
    18   //校验码常数 
    19   string LastCode="10X98765432"
    20   //新身份证号 
    21   string perIDNew; 
    22 
    23   perIDNew=perIDSrc.Substring(0,6);
    24   //填在第6位及第7位上填上‘1’,‘9’两个数字 
    25   perIDNew += "19"
    26 
    27   perIDNew += perIDSrc.Substring(6,9); 
    28 
    29   //进行加权求和 
    30   forint i=0; i<17; i++
    31   
    32    iS += int.Parse(perIDNew.Substring(i,1)) * iW[i]; 
    33   }
     
    34     
    35   //取模运算,得到模值 
    36   int iY = iS%11;
    37   //从LastCode中取得以模为索引号的值,加到身份证的最后一位,即为新身份证号。 
    38   perIDNew += LastCode.Substring(iY,1); 
    39
    40   return perIDNew;
    41  }
     
    42
    43
    44
    45    
    46    Helper methods
    64}
  • 相关阅读:
    通过DataSet操作XML
    什么是网站流量
    JavaScript总结(2)网页上显示时间
    对xml操作的主要方法
    xml保存图片和读取图片(三)
    SharePoint初探sharepoint 安装宝典(2)
    SharePoint初探启用wss的全文搜索(6)
    转载:sharepoint portal server2003安装小记
    SharePoint初探装完Wss后,无法创建或打开原有Web项目问题(7)
    SharePoint初探SharePoint网站整理(8)
  • 原文地址:https://www.cnblogs.com/goody9807/p/559378.html
Copyright © 2011-2022 走看看