2 回答
TA贡献1854条经验 获得超8个赞
Private Sub Command1_Click()
Dim n As String, h As String, i As Integer, c As String
n = Trim(Text1.Text)
If Not (IsNumeric(n) And Val(n) > 0 And Int(n) = Val(n)) Then '判断n非数字、非正数、非整数情况
MsgBox "输入数字符n非正整数,请确认退出!", vbOKOnly
Exit Sub
End If
h = Hex(Val(n)) '将n转换成16进制
c = ""
For i = 1 To Len(h)
c = c & Hex2Bin(Mid(h, i, 1))
Next
Print c
End Sub
Function Hex2Bin(ByVal str As String) '自定义函数16进制转换成2进制
Select Case UCase(str)
Case "0": Hex2Bin = "0000"
Case "1": Hex2Bin = "0001"
Case "2": Hex2Bin = "0010"
Case "3": Hex2Bin = "0011"
Case "4": Hex2Bin = "0100"
Case "5": Hex2Bin = "0101"
Case "6": Hex2Bin = "0110"
Case "7": Hex2Bin = "0111"
Case "8": Hex2Bin = "1000"
Case "9": Hex2Bin = "1001"
Case "A": Hex2Bin = "1011"
Case "B": Hex2Bin = "1100"
Case "C": Hex2Bin = "1101"
Case "D": Hex2Bin = "1110"
Case "E": Hex2Bin = "1111"
End Select
End Function
- 2 回答
- 0 关注
- 316 浏览
添加回答
举报