计算ISBN的校验位 [英] Calculating check digit for ISBN

查看:121
本文介绍了计算ISBN的校验位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上不是家庭作业,我只是在下周开始计算机科学之前浏览一本离散数学书中的一些问题。

This isn't actually homework, I'm just looking through some questions in a discrete maths book before I start computer science next week.

无论如何,其中之一这些问题要求我编写一个程序来执行此算法(对此进行了解释)。我最喜欢的部分是如何将9位数字取为整数并将其拆分为单个整数,以便可以对每个数字进行计算。

Anyway, one of the questions asks me to write a program to perform this algorithm (which it explains). The part I'm stuck with is how to take the 9 digit number and "split" it into single integers, so the calculations can be performed on each digit.

I想过将数字除以100,000,000,然后取其整数值以获得第一个数字,但是我不确定如何获得其他数字。

I thought of dividing the number by 100,000,000 and then taking the integer value of this to get the first digit, but I'm not sure how to get the others.

如果是用PHP还是其他我可以使用explode()的东西,但是我想这不是重点:P

If this was in PHP or something I could just use explode(), but I guess that's not the point here :P

推荐答案

使用mod(%)和divide(/)运算符。

You can use the mod(%) and divide(/) operator.

N%10将给您最后一位数字。
N / 10(整数除法)将删除最后一位数字。

N%10 would give you the last digit. N/10 (integer division) will remove the last digit.

您可以继续操作直到没有更多数字为止。

You can continue till you have no more digits.

这篇关于计算ISBN的校验位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆