vb中把十进制转换为二进制的程序怎么写 急求 T_T

2024-12-04 10:35:30
推荐回答(2个)
回答1:

Private Sub Command1_Click()
Dim n As Long
n = Val(Text1.Text)
Text2.Text = ""
Do While n > 0
Text2.Text = (n Mod 2) & Text2.Text
n = n \ 2
Loop
End Sub

回答2:

Option Explicit
Dim sBin As String
Dim sHex As String
Private Sub Command1_Click()
sHex = Hex(Val(Text1))
Text2 = sHex
HexToBin (sHex)
Text3 = sBin
sBin = ""
End Sub

Private Sub Form_Load()
Text1 = ""
End Sub

Public Function HexToBin(ByVal sHex As String) As String '处理16进制转换2进制代码
Const s1 = "0000101001101111000", s2 = "0125A4936DB7FEC8"
Dim i As Integer
sHex = UCase(sHex)
For i = 1 To Len(sHex)
sBin = sBin & Mid(s1, InStr(1, s2, Mid(sHex, i, 1)), 4)
Next i
End Function