Validation, Verification and Testing: Question 5

Syllabus 7.5

Structured 6 marks

A school library assigns every book a 6-digit BookID, then adds a 7th check digit so that a librarian can spot a mistyped code if the barcode scanner fails and the code has to be entered by hand.

The check digit is calculated as follows:

  • Starting from the rightmost of the 6 digits, multiply that digit by 3.
  • Multiply the next digit to its left by 1.
  • Continue alternating ×3, ×1, ×3, ×1, ×3, ×1 all the way to the leftmost (6th) digit.
  • Add together all six results.
  • The check digit is whatever must be added to this total to reach the next multiple of 10 (if the total already ends in 0, the check digit is 0).

(a) Calculate the check digit for the BookID 481526, showing your working. [3]

(b) Write the complete 7-digit code, including the check digit, that would be printed on the book's label. [1]

(c) Describe how this check digit is used to validate the BookID when it is next entered into the library system. [2]

Show worked solution Hide worked solution

Worked solution

Part (a): Calculating the check digit

Write out BookID 481526 and label each digit by its position counting from the right:

Digit481526
Position from right6th5th4th3rd2nd1st
Weight×1×3×1×3×1×3
Result424115218

Adding the results: 4 + 24 + 1 + 15 + 2 + 18 = 64.

The next multiple of 10 at or above 64 is 70, so the check digit is 70 − 64 = 6.

[3 marks]: [1] for correctly applying the ×3/×1 weighting from the rightmost digit, [1] for the correct total, 64, [1] for the correct check digit, 6.

Part (b): The complete code

The check digit is added after the original 6 digits, so the full code printed on the label is:

481526 + 6 = 4815266

[1 mark] for the correct 7-digit code.

Part (c): How the check digit validates input

A check digit is a validation check: it doesn’t need to be compared against any external source, because it is entirely self-contained within the code itself. When 4815266 is next typed into the library system (for example, because the barcode failed to scan), the system:

  1. Takes the first 6 digits (481526) and recalculates the check digit using the same ×3/×1 rule.
  2. Compares this recalculated check digit with the 7th digit that was actually entered (6).
  3. If the two values match, the code is accepted as correctly entered.
  4. If the two values do not match. For example, if a digit was mistyped or two digits were swapped. The code is rejected, and the librarian is prompted to enter it again.

[2 marks]: [1] for describing the recalculation from the first 6 digits, [1] for describing the comparison with the entered check digit and the accept/reject outcome.

Final answers

  • (a) Check digit = 6 (total = 64, next multiple of 10 = 70, 70 − 64 = 6).
  • (b) Full code = 4815266.
  • (c) Recalculate the check digit from the first 6 digits and compare it with the 7th digit entered; accept if they match, reject if they don’t.