checkdigit calculation for HP-17b
|
07-28-2015, 06:48 PM
Post: #17
|
|||
|
|||
RE: checkdigit calculation for HP-17b
Quoting myself:
(07-26-2015 07:29 PM)Gerson W. Barbosa Wrote: C=10*MOD(MOD(0*L(T:0)+Σ(I:1:9:1:0*L(T:G(T)+I*MOD(N:10))+(10-I) I found out my first example was wrong, it should be 09, not 00. The algorithm I use is different from the official one [ function TestaCPF(strCPF) ], but I've managed to fix it so that it always gives the same results: C=10*MOD(MOD(0*L(T:0)+L(S:Σ(I:1:9:1:0*L(T:G(T)+I*MOD(N:10))+(10-I)*MOD(N:10) +0*L(N:IDIV(N:10)))):11):10)+MOD(MOD(G(T)+9*IDIV((MOD(G(S):11)):10):11):10) 123 456 789 --> 9 (09 actually, since we have two checking digits) 976 431 258 --> 64 777 777 777 --> 77 Here are the equivalent Free Pascal code and results: Code:
It intrigues me a bit why this more simple algorithm works, but I am not nearly as diligent as Don to find the reason. Code:
Gerson. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)