View Single Post
Old 01-04-2022, 02:52 PM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: ISBN10 to ISBN13

With the upcoming migration to Qt6, I was looking into whether I could use Action Chains single-field edit to replace the ISBN conversion feature in the (possibly now unmaintained ) Library Codes plugin.

According to this, here's the steps I would need to take:

1. Take the ISBN-10. (Also remove any dashes/spaces from that.)
2. Drop the last digit.
3. Add "978" to the beginning.
4. Calculate the check digit.

Steps 1-3 seem to be easy enough (I'm working on pulling it together in the template tester) but calculating the check digit seems to be the sticky part and I'm not entirely sure how to do it. From the link above:

Quote:
3 In this and the next three stages we have to calculate the new check digit to append to the twelve digits from step 2. We take each of the 12 digits from step 2, one by one, and multiply them by a number. We multiply the first digit by 1, the second digit by 3, the third digit by 1 again, the fourth digit by 3 again, and so on, alternating 1 and 3 until we get to the twelfth digit.

Here's what I got. Did you get the same?

Code:
9 x 1 = 9
7 x 3 = 21
8 x 1 = 8
1 x 3 = 3
8 x 1 = 8
6 x 3 = 18
1 x 1 = 1
9 x 3 = 27
7 x 1 = 7
2 x 3 = 6
7 x 1 = 7
1 x 3 = 3
4 Now add up all 12 of the answers you got in step 3.
Code:
9 + 21 + 8 + 3 + 8 + 18 + 1 + 27 + 7 + 6 + 7 + 3 = 118
5 Take the answer from step 4 and perform a modulo 10 division. A modulo 10 division is also called casting out 10s. It's just the remainder when you do a whole number division (as opposed to a decimal division where you expect a decimal fraction answer).

118 mod 10 = 8. 118 divided by 10 = 11 remainder 8. We're interested in just the remainder.

Code:
8
6 Final step of calculating the check digit for a ISBN-13. Take the result from step 5. If it is zero, then the check digit is zero. If the result from step 5 isn't zero, then subtract the result from step 5 from the number 10. That result is the check digit.

Code:
10 - 8 = 2.
7 Final step of converting our ISBN-13 from the ISBN-10 is to append the check digit arrived at in step 6 onto the end of the 12 digits we arrived at in step 2.

Code:
9781861972712
And that's it.
I also found this Python code snippet, but I am not sure how to turn that into template language (EDIT: or maybe I can turn it into a template function? not sure).


Last edited by ownedbycats; 01-04-2022 at 03:31 PM.
ownedbycats is offline   Reply With Quote