香港商業登記證(BR)中第8個數字是驗證碼。儘管號碼很長,計算驗證碼 (CHECK DIGIT)只用到首7位數字。
以商業登記證36780058為例,此商業登記證的CHECK DIGIT為8。
按以下公式計算︰
先計算
第1位數字 * 2 加
第2位數字 * 9 加
第3位數字 * 8 加
第4位數字 * 7 加
第5位數字 * 4 加
第6位數字 * 3 加
第7位數字 * 2
的總和;
以36780058為例
3 * 2 = 6
6 * 9 = 54
7 * 8 = 56
8 * 7 = 56
0 * 4 = 0
0 * 3 = 0
5 * 2 = 10
總和是182。
然後計算182除10的餘數,如果餘數是零,則驗證碼 (CHECK DIGIT)是零;否則用10減剛才的餘數便是驗證碼 (CHECK DIGIT)。
182 除 10,餘數是2
10 - 2 = 8
因此驗證碼 (CHECK DIGIT)是 8。
謝謝
2017年5月6日 星期六
如何計算香港身份證驗證碼 (CHECK DIGIT)?
以身份證A123456(3)為例,此身份證的CHECK DIGIT為3。
首先將身份證中的英文字母轉為數字,A=1, B=2, C=3, .... Z=26。
然後按以下公式計算︰
先計算
第1位數字 * 8 加
第2位數字 * 7 加
第3位數字 * 6 加
第4位數字 * 5 加
第5位數字 * 4 加
第6位數字 * 3 加
第7位數字 * 2
的總和;
以A123456(3)為例
A * 8 = 1 * 8 = 8
1 * 7 = 1 * 7 = 7
2 * 6 = 2 * 6 = 12
3 * 5 = 3 * 5 = 15
4 * 4 = 4 * 4 = 16
5 * 3 = 5 * 3 = 15
6 * 2 = 6 * 2 = 12
總和是85。
然後計算85除11的餘數,再用11減去剛才的餘數便是驗證碼 (CHECK DIGIT)。
85 除 11,餘數是8
11 - 8 = 3
因此驗證碼 (CHECK DIGIT)是 3。
如最後計算出來的驗證碼 (CHECK DIGIT)是10,以A表示;
首先將身份證中的英文字母轉為數字,A=1, B=2, C=3, .... Z=26。
然後按以下公式計算︰
先計算
第1位數字 * 8 加
第2位數字 * 7 加
第3位數字 * 6 加
第4位數字 * 5 加
第5位數字 * 4 加
第6位數字 * 3 加
第7位數字 * 2
的總和;
以A123456(3)為例
A * 8 = 1 * 8 = 8
1 * 7 = 1 * 7 = 7
2 * 6 = 2 * 6 = 12
3 * 5 = 3 * 5 = 15
4 * 4 = 4 * 4 = 16
5 * 3 = 5 * 3 = 15
6 * 2 = 6 * 2 = 12
總和是85。
然後計算85除11的餘數,再用11減去剛才的餘數便是驗證碼 (CHECK DIGIT)。
85 除 11,餘數是8
11 - 8 = 3
因此驗證碼 (CHECK DIGIT)是 3。
如最後計算出來的驗證碼 (CHECK DIGIT)是10,以A表示;
============更新============
先把英文換成數字,A=10,B=11,C=12,............Z=35
看開首是一個英文字還是兩個英文字
如果是一個英文字
總和S = 36 * 9 + 英文字 * 8
如果是兩個英文字
總和S = 英文字1 * 9 + 英文字2 * 8
之後的六位數字分別乘以7,6,5,4,3,2
把總和S 除11,得到餘數R
11-R就是CHECK DIGIT
以A123456(3)為例
A = 10
36 * 9 = 324
A * 8 = 10 * 8 = 80
1 * 7 = 1 * 7 = 7
2 * 6 = 2 * 6 = 12
3 * 5 = 3 * 5 = 15
4 * 4 = 4 * 4 = 16
5 * 3 = 5 * 3 = 15
6 * 2 = 6 * 2 = 12
總和是481。
然後計算481除11的餘數,再用11減去剛才的餘數便是驗證碼 (CHECK DIGIT)。
481 除 11,餘數是8
11 - 8 = 3
因此驗證碼 (CHECK DIGIT)是 3。
如最後計算出來的驗證碼 (CHECK DIGIT)是10,以A表示;
36 * 9 = 324
A * 8 = 10 * 8 = 80
1 * 7 = 1 * 7 = 7
2 * 6 = 2 * 6 = 12
3 * 5 = 3 * 5 = 15
4 * 4 = 4 * 4 = 16
5 * 3 = 5 * 3 = 15
6 * 2 = 6 * 2 = 12
總和是481。
然後計算481除11的餘數,再用11減去剛才的餘數便是驗證碼 (CHECK DIGIT)。
481 除 11,餘數是8
11 - 8 = 3
因此驗證碼 (CHECK DIGIT)是 3。
如最後計算出來的驗證碼 (CHECK DIGIT)是10,以A表示;
2017年5月3日 星期三
[DB2] Frequently used command (update from time to time)
db2 set schema gmp
Tell the system we are using schema gmp, so next time we can just type the table name.
e.g. select * from tb_user
db2 list node directory
db2 list database show detail
connect to [dbname] user [username] using [password]
select row_number() over( a.name ) r from table a where a.id = ?
length( str )
returns the byte length of [str]
e.g. select length('陳大文') from sysibm.sysdummy1;
Result is 9 because each Chinese character occupies 3 bytes.
substr( str, [start], [length] )
returns the sub string of length [length] in [str] from the [start] byte.
e.g. select substr( 'apple', 2, 2 ) from sysibm.sysdummy1;
returns "pp"
Warning!!! Substr() is not appropriate for strings containing unicode characters
character_length( str, [encoding] )
returns the character length of [str]
e.g. select character_length('陳大文', CODEUNITS32) from sysibm.sysdummy1;
Result is 9 because each Chinese character occupies 3 bytes.
substring( str, [start], [length], [encoding] )
returns the sub string of length [length] in [str] from the [start] byte.
e.g. select substring('陳大文', 2, 1, CODEUNITS32) from sysibm.sysdummy1;
returns "大"
If you want to go through each character of a string, remember to use character_length( str, [encoding] ) to count the number of character first, then for each character, use length() to check if it is a unicode character, thanks.
Using "NOT IN"
select * from table a where a.id not in (1,2,3)
minus
select * from table a where a.id in (1,2,3)
export to c:\abc\table.csv of del
select * from table a
select * from syscat.tables where tabname like 'ABC%'
select * from syscat.columns where tabname like 'ABC%' and colname like 'ABC%'
select * from syscat.indexes where ...
select * from syscat.procedures where procname like 'ABC%'
select * from syscat.functions where funcname like 'ABC%'
Tell the system we are using schema gmp, so next time we can just type the table name.
e.g. select * from tb_user
db2 list node directory
db2 list database show detail
connect to [dbname] user [username] using [password]
select row_number() over( a.name ) r from table a where a.id = ?
How to identify unicode characters in DB2?
length( str )
returns the byte length of [str]
e.g. select length('陳大文') from sysibm.sysdummy1;
Result is 9 because each Chinese character occupies 3 bytes.
substr( str, [start], [length] )
returns the sub string of length [length] in [str] from the [start] byte.
e.g. select substr( 'apple', 2, 2 ) from sysibm.sysdummy1;
returns "pp"
Warning!!! Substr() is not appropriate for strings containing unicode characters
character_length( str, [encoding] )
returns the character length of [str]
e.g. select character_length('陳大文', CODEUNITS32) from sysibm.sysdummy1;
Result is 9 because each Chinese character occupies 3 bytes.
substring( str, [start], [length], [encoding] )
returns the sub string of length [length] in [str] from the [start] byte.
e.g. select substring('陳大文', 2, 1, CODEUNITS32) from sysibm.sysdummy1;
returns "大"
If you want to go through each character of a string, remember to use character_length( str, [encoding] ) to count the number of character first, then for each character, use length() to check if it is a unicode character, thanks.
Avoid using "not exist", use "minus" if possible
Using "NOT IN"
select * from table a where a.id not in (1,2,3)
Same result using "minus"
select * from table aminus
select * from table a where a.id in (1,2,3)
Export csv
export to c:\abc\table.csv of del
select * from table a
Check tables / columns / indexes / procedures
select * from syscat.tables where tabname like 'ABC%'
select * from syscat.columns where tabname like 'ABC%' and colname like 'ABC%'
select * from syscat.indexes where ...
select * from syscat.procedures where procname like 'ABC%'
select * from syscat.functions where funcname like 'ABC%'
訂閱:
文章 (Atom)