An algorithm for upgrading from 15-bit ID to 18-bit in C #

Source: Internet
Author: User
Tags constant

1 using System;
2 using System.Collections
3
4 public class MyClass
5 {
6 public static Voi D Main ()
7 {
8 Console.WriteLine (per15to18 ("429005811009091"));
9 RL ();
"
"
Publ IC static string Per15to18 (String peridsrc)
{
# int is = 0;

16//Weighted factor constant
Int[] iw=new int[ ]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
18//Checksum code constant
lastcode= "10x98765432";
20//New ID number
string peridnew;

Peridnew=p Eridsrc.substring (0,6);
24//Fill in 6th and 7th for ' 1 ', ' 9 ' two number
Peridnew + + + + peridnew + + peridsrc.substring (6,9);
28
29//weighted sum
for (int i=0; i<17; i++)
-{
is + = Int. Parse (peridnew.substring (i,1)) * Iw[i];
33}
35
//modulo operation, get modulus
+ int iY = is%11
37//from Lastcode to take the value of modulo index number, add to the last one of the ID card, that is, the new ID number.
Peridnew + = lastcode.substring (iy,1);
Peridnew;r> (
)


\
-Helper Methods#region helper methods
$
-private static void WL (obj ECT text, params object[] args)
$ {
Console.WriteLine (text. ToString (), args);
51}

The private static void RL ()
{
-console.readline ();
"
"
void Break ()
System.Diagnostics.Debugger.Break {
():
"
"
#endregion
"
" /p>

Http://www.cnblogs.com/goody9807/archive/2006/11/13/559378.html

Related Article

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.