✔ 最佳答案
for the algorithm and VB function, pls check:
http://www.kgv.net/ict-ks4/TheoryTerm2/HKCheckDigit.htm
pls check following C code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{ char cID[7];
int n1, nSum;
int i;
strcpy( cID, argv[1] );
n1 = ( cID[0] - 64 ) % 11;
n1 = ( n1 == 0 ? 11 : n1 );
nSum = n1 * 8;
for ( i = 1; i < 7; i++ )
nSum = nSum + ( ( cID[i] - 48 ) * ( 8 - i ) );
printf( "Check sum : %d", 11 - ( nSum % 11 ) );
return 0;
}
hope can help u
2006-11-29 15:10:09 補充:
this C program has no any validation. u need to enter a correct HKID. for example, 'a123456' is error and need to enter 'A123456'.
2006-11-29 16:10:53 補充:
Sorry.if the last calculation is 10, the check digit would be 'A'. Please change the last printf statement. if ( 11 - ( nSum % 11 ) == 10 ) printf( "Check sum : A" ); else printf( "Check sum : %d", 11 - ( nSum % 11 ) );
2006-11-30 15:33:44 補充:
So sorry. also need to handle the check sum is 11. just change last printf statement.if ( 11 - ( nSum % 11 ) == 10 )printf( “Check sum : A” );elseprintf( “Check sum : %d”, ( 11 - ( nSum % 11 ) ) % 11 );