- 分享
- 0
- 人气
- 0
- 主题
- 31
- 帖子
- 2093
- UID
- 194067
- 积分
- 1416
- 阅读权限
- 18
- 注册时间
- 2009-1-21
- 最后登录
- 2016-1-13
- 在线时间
- 6900 小时
|
各位帅气英俊,能力过人的大大们
请问一下,要实现这个功能,该怎么办?
我在MSDN社区那里找到了以下的:
'由ASCII码转BCD码
Function AscToBCD(ASCII() As Byte) As Byte()
Dim i As Integer
Dim bTemp As Byte
Dim bBCD() As Byte
Dim bAsc() As Byte
Dim bA As Byte
Dim bB As Byte
Dim intLen As Integer
intLen = UBound(ASCII)
If intLen Mod 2 = 0 Then intLen = intLen + 1
ReDim bAsc(intLen) As Byte
ReDim bBCD((intLen + 1) / 2 - 1) As Byte
For i = 0 To UBound(ASCII)
bAsc(i) = ASCII(i)
Next
If intLen > i Then bAsc(intLen) = &H0 '对数组不是偶数的补位
For i = 0 To intLen
If bAsc(i) < Asc("0") Then
bAsc(i) = Asc("0")
ElseIf ((bAsc(i) > Asc("9")) And (bAsc(i) < Asc("A"))) Then
bAsc(i) = Asc("0")
ElseIf ((bAsc(i) > Asc("F")) And (bAsc(i) < Asc("a"))) Then
bAsc(i) = Asc("0")
ElseIf (bAsc(i) > Asc("f")) Then
bAsc(i) = Asc("0")
End If
If (bAsc(i) >= Asc("0") And bAsc(i) <= Asc("9")) Then
bA = bAsc(i) - Asc("0")
ElseIf (bAsc(i) >= Asc("a") And bAsc(i) <= Asc("z")) Then
bA = bAsc(i) - Asc("a") + &HA
Else
bA = bAsc(i) - Asc("A") + &HA
End If
i = i + 1
If bAsc(i) < Asc("0") Then
bAsc(i) = Asc("0")
ElseIf ((bAsc(i) > Asc("9")) And (bAsc(i) < Asc("A"))) Then
bAsc(i) = Asc("0")
ElseIf ((bAsc(i) > Asc("F")) And (bAsc(i) < Asc("a"))) Then
bAsc(i) = Asc("0")
ElseIf (bAsc(i) > Asc("f")) Then
bAsc(i) = Asc("0")
End If
If (bAsc(i) >= Asc("0") And bAsc(i) <= Asc("9")) Then
bB = bAsc(i) - Asc("0")
ElseIf (bAsc(i) >= Asc("a") And bAsc(i) <= Asc("z")) Then
bB = bAsc(i) - Asc("a") + &HA
Else
bB = bAsc(i) - Asc("A") + &HA
End If
bBCD((i - 1) / 2) = (bA * 16) Xor bB
Next
AscToBCD = bBCD
End Function
---------------------------------------------------------------
调用BCDToAsc
Private Sub Command1_Click()
Dim bA(3) As Byte
Dim bB() As Byte
Dim i As Integer
bA(0) = Asc("1")
bA(1) = Asc("0")
bA(2) = Asc("a")
bA(3) = Asc("F")
bB = AscToBCD(bA)
For i = 0 To UBound(bB)
MsgBox Hex(bB(i))
Next
End Sub
结果为 &H10 和&HAF
---------------------------------------------------------------
'由BCD转ASCII码
Function BCDToAsc(BCD() As Byte) As Byte()
Dim i As Integer
Dim bTemp As Byte
Dim bAsc() As Byte
Dim intLen As Integer
intLen = UBound(BCD)
ReDim bAsc(intLen * 2 + 1) As Byte '重新定义数组上标
For i = 0 To intLen
bTemp = (BCD(i) / 16) And &HF
If bTemp > 9 Then
bAsc(i * 2) = bTemp + Asc("A") - 10
Else
bAsc(i * 2) = bTemp + Asc("0")
End If
bTemp = BCD(i) And &HF
If bTemp > 9 Then
bAsc(i * 2 + 1) = bTemp + Asc("A") - 10
Else
bAsc(i * 2 + 1) = bTemp + Asc("0")
End If
Next
BCDToAsc = bAsc
End Function
-----------------------------------------------------------------------------------------------------------------
问题来啦,这堆火星,我看没啊
谁能把这些文言文转换为白话文
希望你们能给我解答
万分感激!
em0068 em0068
P/s:我是OxfordExe2 |
|