13位ISBN的校验位计算方法
(模数10 余数 0-9 差数 1-10 校验位:0-9)
13位ISBN校验位改变了10位ISBN的计算方法,采用奇数偶数位算法,模数也改为10,所以新的ISBN中将不出现X校验码。13位ISBN的最后一位数字为校验位,数值范围由0至9,其计算方法如下 :
(1) 用1分别乘书号的前12位中的奇数位, 用3乘以偶数位:(位数从左到右为13位到2位)
(2) 将各乘积相加,求出总和 ;
(3) 将总和除以10,得出余数;
(4) 将10减去余数后即为校验位。如相减后的数值为10,校验位则为0。
/**/
/// <summary>
/// ISBN-10位转换成ISBN-13位方法
/// </summary>
/// <param name="Isbn10">ISBN-10编号</param>
/// <returns>ISBN-13编号</returns>
public static string GetIsbn13( string Isbn10)
... {
if (Isbn10.Length == 10)
...{
string Location13 = "9";
string Location12 = "7";
string Location11 = "8";
string Location10 = Isbn10.Substring(0,1);
string Location09 = Isbn10.Substring(1, 1);
string Location08 = Isbn10.Substring(2, 1);
string Location07 = Isbn10.Substring(3, 1);
string Location06 = Isbn10.Substring(4, 1);
string Location05 = Isbn10.Substring(5, 1);
string Location04 = Isbn10.Substring(6, 1);
string Location03 = Isbn10.Substring(7, 1);
string Location02 = Isbn10.Substring(8, 1);
int IsbnSUM = Convert.ToInt16(Location13) + Convert.ToInt16(Location11) + Convert.ToInt16(Location09) + Convert.ToInt16(Location07) + Convert.ToInt16(Location05) + Convert.ToInt16(Location03) + (Convert.ToInt16(Location12) + Convert.ToInt16(Location10) + Convert.ToInt16(Location08) + Convert.ToInt16(Location06) + Convert.ToInt16(Location04) + Convert.ToInt16(Location02)) * 3;
string Location01 =Convert.ToString((10 - IsbnSUM % 10)%10);
string Isbn13 = Location13 + Location12 + Location11 + Location10 + Location09 + Location08 + Location07 + Location06 + Location05 + Location04 + Location03 + Location02 + Location01;
return Isbn13;
}
else
...{
return null;
}
}
/// ISBN-10位转换成ISBN-13位方法
/// </summary>
/// <param name="Isbn10">ISBN-10编号</param>
/// <returns>ISBN-13编号</returns>
public static string GetIsbn13( string Isbn10)
... {
if (Isbn10.Length == 10)
...{
string Location13 = "9";
string Location12 = "7";
string Location11 = "8";
string Location10 = Isbn10.Substring(0,1);
string Location09 = Isbn10.Substring(1, 1);
string Location08 = Isbn10.Substring(2, 1);
string Location07 = Isbn10.Substring(3, 1);
string Location06 = Isbn10.Substring(4, 1);
string Location05 = Isbn10.Substring(5, 1);
string Location04 = Isbn10.Substring(6, 1);
string Location03 = Isbn10.Substring(7, 1);
string Location02 = Isbn10.Substring(8, 1);
int IsbnSUM = Convert.ToInt16(Location13) + Convert.ToInt16(Location11) + Convert.ToInt16(Location09) + Convert.ToInt16(Location07) + Convert.ToInt16(Location05) + Convert.ToInt16(Location03) + (Convert.ToInt16(Location12) + Convert.ToInt16(Location10) + Convert.ToInt16(Location08) + Convert.ToInt16(Location06) + Convert.ToInt16(Location04) + Convert.ToInt16(Location02)) * 3;
string Location01 =Convert.ToString((10 - IsbnSUM % 10)%10);
string Isbn13 = Location13 + Location12 + Location11 + Location10 + Location09 + Location08 + Location07 + Location06 + Location05 + Location04 + Location03 + Location02 + Location01;
return Isbn13;
}
else
...{
return null;
}
}