这是将两个 C40 编码字节 (i1,i2) 转换回它们的 ASCII 码号的伪代码。即使是伪代码,它也应该很容易用任何语言实现。
INPUT: Two bytes (i1,i2) resulting from C40 encoding
OUTPUT: Array [] of decoded ASCII characters
if i1 == 0xFE then // if i1 is unlatch 0xFE, then i2 is char encoded as ASCII + 1
return [char(i2-1)]
else // below '/' denotes integer division
val16 = (i1*256) + i2
u1 = (val16-1) / 1600
u2 = (val16 - (u1*1600)) / 40
u3 = v16 - (u1*1600) - (u2*40) - 1
// u1,u2,u3 are the chars with their C40 code numbers
// now convert them back to ASCII code numbers
ascii_chars = []
for u in [u1,u2,u3] do
if u == 3 then // C40 3 is space, add 32 to get ascii value
ascii_chars.append(chr(32))
else if u >=4 and u <= 13 then // C40 number range, add 40 to get ascii value
ascii_chars.append(chr(u+44))
else if u >= 14 and u <= 39 then // C40 range A-Z, add 51 to get ascii value
ascii_chars.append(chr(u+51))
return ascii_chars