vb进制转换与赋值问题
来源:百度知道 编辑:UC知道 时间:2024/09/12 21:54:18
现在我在SBUF里面获取了一个2位16进制的数,比如 E2
思路过程:把它转成2进制数 1110 0010
然后进行单独赋值,每个数字赋给一个量,
例如 a=1 b=1 c=1 d=0 e=0 f=0 g=1 h=0
就是这样,我只需要赋值的量而已,中间过程可以不写出哦。
dim a(7) as integer,i as integer,R as string
r="&HE2"
for i=0 to 7
a(i)=r mod 2
r=r\2
next i
运行结果:a(7)=1 a(6)=1 a(5)=1 a(4)=0 a(3)=0 a(2)=0 a(1)=1 a(0)=0
哦
Function D_To_B(ByVal Dec As Long) As String
Do
D_To_B = Dec Mod 2 & D_To_B
Dec = Dec \ 2
Loop While Dec
End Function
Function B_To_D(ByVal Bin As String) As Integer
Dim i As Long
For i = 1 To Len(Bin)
B_To_D = B_To_D * 2 + Val(Mid(Bin, i, 1))
Next i
End Function
Function H_To_B(ByVal Hex As String) As String
Dim i As Long
Dim B As String
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, i, 1)
Case "0": B = B & "0000"
Case "1": B = B & "0001"
Case "2": B = B & "0010"