97 lines
3.3 KiB
Plaintext
97 lines
3.3 KiB
Plaintext
|
|
|||
|
The following comes from Page 54 of Revenue Canada
|
|||
|
Taxation publication MC42. ( Jan 1,85. Machine
|
|||
|
computation of ......)
|
|||
|
Keith (PC1155)
|
|||
|
|
|||
|
--------------------------------------------------
|
|||
|
|
|||
|
The Social Insurance Number contains nine digits.
|
|||
|
The number consists of eight assigned digits, with
|
|||
|
the ninth digit being constructed from the first
|
|||
|
eight and acting as a check digit. The accuracy of
|
|||
|
transcription of the number may be verified using
|
|||
|
the standard modulus 10 check digit formula.
|
|||
|
|
|||
|
Briefly, the check digit is established by
|
|||
|
considering the unit digit of the basic number and
|
|||
|
each alternate digit to the left to be a whole
|
|||
|
number. This number is multiplied by two and the
|
|||
|
digits in the product and the intervening digits
|
|||
|
which were not inflated are cross added. The sum
|
|||
|
is subtracted from the next highest number ending
|
|||
|
in zero. The difference is the check digit.
|
|||
|
|
|||
|
For the purpose of verifying the Social Insurance
|
|||
|
Number, you must consider the basic Social
|
|||
|
Insurance Number which consists of the first eight
|
|||
|
digits. The example below may better illustrate
|
|||
|
the verication method.
|
|||
|
|
|||
|
Check
|
|||
|
Basic No. Digit
|
|||
|
|
|||
|
Social Insurance Number provided
|
|||
|
in your employee's record . . . . . . 123 456 78 2
|
|||
|
|
|||
|
Make a number from unit position
|
|||
|
and each alternate position to the
|
|||
|
left . . . . . . . . . . . . . . . . 2 4 6 8
|
|||
|
|
|||
|
Add the number to itself . . . . . . 2 4 6 8
|
|||
|
-----------
|
|||
|
Sum . . . . . . . . . . . . . . . . . 4 9 3 6
|
|||
|
|
|||
|
Cross add the digits in the sum
|
|||
|
(4 + 9 + 3 + 6) = . . . . . . . . . . . . . . . . . . . . 22
|
|||
|
|
|||
|
Cross add intervening digits
|
|||
|
(1 + 3 + 5 + 7) = . . . . . . . . . . . . . . . . . . . . 16
|
|||
|
---
|
|||
|
Total . . . . . . . . . . . . . . . . . . . . . . . . . . 38
|
|||
|
|
|||
|
If the total is a multiple of 10, the check
|
|||
|
digit is 0, otherwise subtract from the next
|
|||
|
highest number ending in zero. . . . . . . . . . . . . . . 40
|
|||
|
|
|||
|
Check digit is . . . . . . . . . . . . . . . . . . . . . . 2
|
|||
|
|
|||
|
--------------------------------------------------
|
|||
|
|
|||
|
Below is a BASIC code fragment that checks the number entered.
|
|||
|
Note that the number is a string.
|
|||
|
|
|||
|
REM SIN$ IS THE NUMBER TO BE CHECKED
|
|||
|
820 FAIL = 0
|
|||
|
IF LEN(SIN$) <> 9 THEN FAIL = 1 : GOTO 830
|
|||
|
IF VAL(SIN$) = 0 THEN FAIL = 1 : GOTO 830
|
|||
|
|
|||
|
REM GET ALTERNATE DIGITS
|
|||
|
X$="" : X=0
|
|||
|
FOR Z%=1 TO 4
|
|||
|
X$=X$+MID$(SIN$,Z%*2,1)
|
|||
|
NEXT Z%
|
|||
|
|
|||
|
REM MULTIPLY BY 2
|
|||
|
X$=STR$(VAL(X$)*2)
|
|||
|
|
|||
|
REM CROSS ADD THE DIGITS
|
|||
|
FOR Z%=1 TO LEN(X$)
|
|||
|
X=X+VAL(MID$(X$,Z%,1))
|
|||
|
NEXT Z%
|
|||
|
|
|||
|
REM ADD THE INTERVENING DIGITS
|
|||
|
FOR Z%=1 TO 7 STEP 2
|
|||
|
X=X+VAL(MID$(SIN$,Z%,1))
|
|||
|
NEXT Z%
|
|||
|
|
|||
|
REM SUBTRACT FROM THE NEXT MULTIPLE OF 10
|
|||
|
X=(10-(X MOD 10)) MOD 10
|
|||
|
|
|||
|
REM CHECK THE RESULT AGAINST THE LAST DIGIT OF THE SIN$
|
|||
|
IF X <> VAL(RIGHT$(SIN$,1)) THEN FAIL = 1
|
|||
|
|
|||
|
830 IF FAIL <> 0 THEN PRINT "BAD S.I.N. ";SIN$
|
|||
|
|
|||
|
|
|||
|
|