1,502
社区成员
发帖
与我相关
我的任务
分享Option Explicit
Sub Main()
Dim aBCD() As Byte
Dim lValue As Long
Dim i As Long
aBCD = EncodeBCD(1234)
For i = 0 To 1
Debug.Print Right("0" & Hex(aBCD(i)), 2);
Next
Debug.Print
lValue = DecodeBCD(aBCD)
Debug.Print lValue
End Sub
Function EncodeBCD(ByVal Value As Long) As Byte()
Dim aBCD() As Byte
ReDim aBCD(1)
aBCD(0) = ((Value \ 1000) Mod 10) * 16 + ((Value \ 100) Mod 10)
aBCD(1) = ((Value \ 10) Mod 10) * 16 + (Value Mod 10)
EncodeBCD = aBCD
End Function
Function DecodeBCD(aBCD() As Byte) As Long
DecodeBCD = (aBCD(0) \ 16) * 1000 + (aBCD(0) Mod 16) * 100 _
+ (aBCD(1) \ 16) * 10 + (aBCD(1) Mod 16)
End Function