Wednesday, January 23, 2013

Hong Kong ID Formula (HKID Number Check Digit)

此文之中文版
http://computerterminal.blogspot.hk/2005/11/hkid-calculation.html


I found out form the Google Analystic that 1/8 of the visitors to this site is to the post HKID Calculation and 1/3 of the visitors are from Russia(!!!) and USA. So i decide to write that post in English for them.

HK ID number starts from one English Letter plus 6 digits and end with a check digit in bracket
for example: a123456(7)

Validate the HK ID by the following steps:


1) Replace the leading English alphabet with numberic value following the rules below:

A = 10    B = 11   C = 12   D = 13  E = 14    F = 15

G = 16    H = 17   I = 18     J = 19   K = 20    L = 21M = 22    N = 23  O = 24   P = 25   Q = 26    R = 27S = 28    T = 29   U = 30   V = 31   W = 32   X = 33Y = 34     Z = 35

2) Weighted Total 
Calculation 
   A)If double english alphabet digit,e.g. AB987654(2):
           Total = 324 + 1st Digit x9 + 2nd Digit x8 + 3rd Digit x7 + 4th Digit x6 + 5th Digit x5 + 6th Digit x4 + 7th Digit x3 +8th Digit x2

   B) Else if single english alphabet digit,e.g. E364912(5):
           Total = 324 + 1st Digit x8 + 2nd Digit x7 + 3rd Digit x6 + 4th Digit x5 + 5th Digit x4 + 6th Digit x3 + 7th Digit x2 

3) CheckDigit Calculation

Remaining= Total modulo 11 

IF
a)Remaning = 0:
   CheckDigit = 0

b)Remaning = 1:
   CheckDigit = A

c)Remaning = [2-10]:
   CheckDigit = 11 - Remaining


Example:
HKID:E364912(5)
(PS:E is equal to 14 according to step 1)

324 + 14x8 + 3x7 + 6x6 + 4x5 + 9x4 + 1x3 + 2x2 = 556

556 % 11 = 68

11 - 6 = 5

So E364912(5) is a Valid HKID


No comments: