Calculation Method of Chinese Standard Code (C # code)
Recently I had an ERP project involving book sales, so I spent a few nights studying related things ...... Take the time to sort out some content.
First, understand some necessary Terms and definitions:
---------------------------------------
EAN • UCC prefix
The identifier code assigned by the International Association for item encoding.
---------------------------------------
Check digit
The last digit of the Chinese standard number is calculated by the 12 digits in front of the Verification Code through a specific mathematical algorithm to check the correctness of the Chinese standard number.
---------------------------------------
ISBN
The abbreviation of the International Standard Book Number, which is an identifier of the International Standard Book Number.
---------------------------------------
Publisher
A publishing institution or organization that applies to the ISBN authority in China and obtains the publication number.
---------------------------------------
Group registration group
Work areas designated by the International ISBN management institution by country, geographical region, language and other social groups.
========================================================
Structure of Chinese Standard Book Number:
---------------------------------------
Composition of Chinese Standard Book Number
The Chinese standard number consists of the identifier "ISBN" and 13 digits. The 13 digits are divided into the following five parts:
1) EAN • UCC prefix
2) Group area code
3) publisher number
4) publication serial number
5) Verification Code
When the Chinese standard document number is written or printed, the identifier "ISBN" uses uppercase English letters, leaving half of the Chinese characters blank. The parts of the numbers should be separated by a half-character line. As follows:
Isbn ean • UCC prefix-group area code-publisher code-publication sequence number-Verification Code
Example: ISBN 978-7-5064-2595-7
---------------------------------------
EAN • UCC prefix
The first part of the Chinese standard number. The product identification code provided by the ean ucc System to the ISBN management system.
---------------------------------------
Group Area No.
The second part of the Chinese standard number. It is allocated by the International ISBN authority. China group code is "7 ".
---------------------------------------
Publisher ID
The third part of the Chinese standard number. Identifies the publisher. It can be 2 to 7 characters in length and is set and allocated by the ISBN authority in China.
---------------------------------------
Publication No.
The fourth part of the Chinese standard number. It is managed and compiled by the publisher in the order of publication.
---------------------------------------
Verification Code
The fifth and last part of the Chinese standard number. Calculated using the modulus 10 weighted algorithm.
---------------------------------------
Value range and number of publishers
Publisher number setting range
00 09
100 499
5000 7999
80000 89999
900000 989999
9900000 9999999
The number of publications contained in each publication number (one-to-one correspondence with the above, for example, 00 09 corresponds to 1000000)
1000000
100000
10000
1000
100
10
---------------------------------------
Calculation of the 10-digit Chinese standard number verification code:
Code
/// <Summary>
/// Calculation of the 10-digit Chinese standard number verification code.
/// <Remarks>
/// The 10-digit Chinese standard number verification code is calculated using the weighted algorithm of modulus 11.
///
/// Mathematical formula:
/// Verification code = mod 11 {11-[mod 11 (sum of the weighted product)]}
/// = Mod 11 {11-[mod 11 (248)]}
/// = 5
///
/// Take ISBN 7-5064-2595-5 as an example.
/// </Remarks>
/// </Summary>
/// <Param name = "barCode"> </param>
/// <Returns> </returns>
Public static string GetF10ISBN (string sCode)
{
String coreCode = sCode. Replace ("-","");
CoreCode = coreCode. Substring (0, 9 );
Int sum = 0;
For (int I = 10; I> 1; I --)
{
// From high to low, multiply by (10-i)
Sum + = I * Convert. ToInt32 (coreCode. Substring (10-I), 1 ));
}
String checkCode = "";
If (sum % 11 = 0)
{
CheckCode = "0 ";
}
Else if (sum % 11 = 1)
{
CheckCode = "X ";
}
Else
{
CheckCode = (11-(sum % 11). ToString ();
}
Return string. Concat (coreCode, checkCode );
}
Calculation of the 13-digit Chinese standard number verification code:
Code
/// <Summary>
/// Calculate the verification code of the 13-digit Chinese standard number.
/// <Remarks>
/// The verification code of the 13-digit Chinese standard number is calculated using the weighted algorithm of modulus 10.
///
/// Mathematical formula:
// Verification code = mod 10 {10-[mod 10 (sum of the weighted product of the first 12 digits of the Chinese standard number)]}
/// = Mod 10 {10-[mod 10 (123)]}
/// = 7
///
/// Take ISBN 978-7-5064-2595-7 as an example.
/// </Remarks>
/// </Summary>
/// <Param name = "sCode"> </param>
/// <Returns> </returns>
Public static string GetF13ISBN (string sCode)
{
String coreCode = sCode. Replace ("-","");
CoreCode = coreCode. Substring (0, 12 );
Int oddSum = 0; // odd and
Int evenSum = 0; // an even number and
For (int I = 0; I <12; I ++)
{
If (I % 2 = 0)
{
EvenSum + = Convert. ToInt32 (coreCode. Substring (I, 1 ));
}
Else
{
OddSum + = Convert. ToInt32 (coreCode. Substring (I, 1 ));
}
}
Int sum = oddSum + evenSum * 3;
String checkCode = null;
If (sum % 10 = 0)
{
CheckCode = "0 ";
}
Else
{
CheckCode = (10-(sum % 10). ToString ();
}
Return string. Concat (coreCode, checkCode );
}
The 10-digit Chinese standard number is converted to the 13-digit Chinese Standard Number:
Code
/// <Summary>
/// The Chinese standard number of 10 digits is converted to the Chinese standard number of 13 digits.
/// <Remarks>
/// Convert a 10-digit Chinese standard number to a 13-digit Chinese standard number, and add the EAN • UCC prefix 978 before the first nine digits,
/// Use the verification code calculated by the modulus 10 weighted algorithm to replace the verification code of the 10-digit Chinese standard number.
/// </Remarks>
/// </Summary>
/// <Param name = "s10ISBN"> </param>
/// <Returns> </returns>
Public static string ISBN10T13 (string sISBN)
{
Return GetF13ISBN (string. Concat ("978-", sISBN ));
}
From: http://www.cnblogs.com/ideal35500/archive/2010/11/22/1884711.html