After studying the encoding, we learned the relationship between GB2312 encoding and location code. After trying, we got this program.
Search, no one seemed to write it, so I posted it here.
Original first release:
http://bbs.blueidea.com
http://mytju.com/classcode/
Reprint anytime, use it anytime.
1. Brief description
(1) The definition of the GB2312 standard is actually the location code.
There are 94 rows in total, 94 columns, rows are area codes, and columns are bit numbers.
For example, the area code of the character "ah" is 16 and the bit number is 01, and its position code is 1601.
(2) Each character consists of area code + bit number, accounting for two bytes in total.
Each byte is 01-94, which conflicts with the communication controller 0-31.
Therefore, add the area code and bit number 32 respectively to avoid conflicts.
(3) From the above, each byte is 33-126, which conflicts with ASCII encoding 0-127,
So put the highest position to 1, that is, add 128 to avoid conflicts.
So, in the end, each byte is 161-254.
2. accomplish
The principle is very simple, add or subtract.
I will post the function I completed here directly.
The code copy is as follows:
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FunctionCharToQWM(byValstr)
dimsHex,sHigh,sLow,iLow,iHigh,sResult
sHex=Hex(Asc(str))' Get the encoding of the inner code of the character, such as B0A1, this encoding is in the correct order and there is no need to exchange high and low bits.
sHigh=Left(sHex,2)' gets the encoded high bit, such as B0.
sLow=Right(sHex,2)' gets the encoding low bit, such as A1.
'GB2312 inner code range is &HA1A1--&HFEFE, and each byte is between A1-FE.
ifNOT(sHigh>="A1"ANDsHigh<="FE")then
CharToQWM=""
ExitFunction
endif
ifNOT(sLow>="A1"ANDsLow<="FE")then
CharToQWM=""
ExitFunction
endif
'The GB exchange code only uses 7 bits, and the high position is 1, which is the inner code. In turn, the high position is 0, and the swap code can be obtained.
iLow=Clng("&H"&sLow)-128
iHigh=Clng("&H"&sHigh)-128
'The location code conflicts with the control code 0-31, so after adding 32, the exchange code is the one. In turn, subtract 32.
iLow=iLow-32
iHigh=iHigh-32
'OK, the location code has been obtained.
sResult=""
ifiHigh<10then
sResult=sResult&"0"&Cstr(iHigh)
else