--- title: "Checksum" id: 57000 type: "computer_media" slug: "checksum" url: "http://localhost/computer_media/checksum/" markdown_url: "http://localhost/computer_media/checksum.md" published_at: "2024-10-02T07:20:33+00:00" modified_at: "2026-03-30T21:20:20+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/24_Check.png" excerpt: "Enter six digits one at a time and this program calculates a weighted checksum digit using alternating 1-2 weights and iterative digit reduction." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Utility" slug: "utility" taxonomy: "genre" url: "http://localhost/type/utility/" media_contents: - id: 56732 title: "Timex Sinclair Public Domain Library Tape 1001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1001/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/24_Check.png" media_type_tags: "Utility" --- # Checksum 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 | Variable | Purpose | | --- | --- | | `A`–`F` | The six input digits | | `S` | Running weighted sum, updated in-place during reduction | | `T` | Tens portion of `S` (quotient of division by 10) | | `U` | Units 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. ## 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 ```