gipasoft

Calcolare CheckDigit EAN13

Jun 1st, 2013
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static string getEAN13CheckSum(string valore)
  2. {
  3.     int iSum = 0;
  4.     int iDigit = 0;
  5.  
  6.     // Calculate the checksum digit here.
  7.     for( int i = valore.Length; i >= 1; i-- )
  8.     {
  9.         iDigit = Convert.ToInt32( valore.Substring( i - 1, 1 ) );
  10.         if( i % 2 == 0 )
  11.         {   // odd
  12.             iSum += iDigit * 3;
  13.         }
  14.         else
  15.         {   // even
  16.             iSum += iDigit * 1;
  17.         }
  18.     }
  19.  
  20.     int iCheckSum = ( 10 - ( iSum % 10 )  ) % 10;
  21.     return iCheckSum.ToString();
  22. }
Advertisement
Add Comment
Please, Sign In to add comment