Checksum

This file is part of Timex Sinclair Public Domain Library Tape 1001 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Utility

This program computes a weighted checksum digit for a six-digit number. The user enters each digit individually, after which the program applies alternating weights of 1 and 2 (1, 2, 1, 2, 1, 2) to the digits and sums the results. It then repeatedly extracts and re-sums the decimal digits of that total until a single digit remains, using a cross-sum (digital root) reduction loop at lines 210–240. The final single-digit result is displayed as the check digit.


Program Analysis

Program Structure

The program is straightforward and linear, divided into three logical phases:

  1. Input phase (lines 10–111): Prompts the user to enter six digits one at a time, storing them in variables A through F.
  2. Computation phase (lines 180–240): Applies a weighted sum then reduces it to a single digit.
  3. Output phase (lines 160–290): Displays the original number and the computed check digit.

Checksum Algorithm

Line 180 computes a weighted sum S = A + 2*B + C + 2*D + E + 2*F, applying weights 1 and 2 alternately to each digit position. Lines 210–240 implement a digital root reduction: the sum is split into its tens digit (T = INT(S/10)) and units digit (U = S - T*10), then S is replaced by T + U. This loop repeats until S is a single digit (≤ 9). The result is a form of iterative digit summing rather than a standard modulo-10 check.

Key BASIC Idioms

  • The widely spaced line numbers (10, 30, 50, 70…) leave room for future insertions between input steps.
  • GOTO 210 at line 240 implements a simple conditional loop without a FOR/NEXT construct, appropriate since the iteration count is data-dependent.
  • The trailing comma on line 170’s PRINT statement moves the cursor to the next print zone but doesn’t suppress the newline entirely; combined with the semicolons, this produces a specific layout for the six digits.

Variable Usage

VariablePurpose
AFThe six input digits
SRunning weighted sum, updated in-place during reduction
TTens portion of S (quotient of division by 10)
UUnits portion of S (remainder after division by 10)

Notable Techniques

The digital root loop at lines 210–240 reuses variable S rather than introducing new variables for each iteration, keeping memory use minimal. The reduction is guaranteed to terminate since the digit sum of any positive integer is strictly smaller than the integer itself once it exceeds a single digit.

Bugs and Anomalies

The program accepts any numeric value from INPUT, not just single digits 0–9. Entering a non-digit value (e.g. a multi-digit number or a negative number) will silently produce an incorrect checksum. There is no input validation. Additionally, line 2 (LIST) executes immediately after the auto-run SAVE, causing the program listing to be displayed before the title screen — this is likely an unintentional remnant left in during development.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10001 – 10050.

Related Products

Related Articles

Related Content

Image Gallery

Checksum

Source Code

   1 SAVE "1002%4"
   2 LIST 
   5 REM CHECKSUM PROGRAM
   6 REM NUMBER VERIFICATION
   8 PRINT TAB (10);"CHECKSUM PROGRAM"
   9 PRINT 
  10 PRINT "ENTER DIGIT 1 "
  11 INPUT A
  30 PRINT "ENTER DIGIT 2 "
  31 INPUT B
  50 PRINT "ENTER DIGIT 3 "
  51 INPUT C
  70 PRINT "ENTER DIGIT 4 "
  71 INPUT D
  90 PRINT "ENTER DIGIT 5 "
  91 INPUT E
 110 PRINT "ENTER DIGIT 6 "
 111 INPUT F
 160 PRINT 
 170 PRINT " THE NUMBER IS ";A;B;C;D;E;F,
 180 LET S=A+2*B+C+2*D+E+2*F
 210 LET T=INT (S/10)
 220 LET U=S-T*10
 230 LET S=T+U
 240 IF S>9 THEN GOTO 210
 250 PRINT 
 260 PRINT 
 290 PRINT "   THE CHECKDIGIT IS ";S

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top