vb中怎么从十进制转换成二进制?
我写了一段程序代码,是把十进制转换成二进制,可是运行的时候结果出的一直是错的。麻烦高手帮我看下哪里错了?PrivateSubCommand1_Click()DimnAsL...
我写了一段程序代码,是把十进制转换成二进制,可是运行的时候结果出的一直是错的。麻烦高手帮我看下哪里错了?
Private Sub Command1_Click()
Dim n As Long, p As Integer, a As Integer
a = Text1.Text
Do While a > 0
p = a Mod 2
a = a \ 2
n = p & n
Loop
Text2.Text = n 展开
Private Sub Command1_Click()
Dim n As Long, p As Integer, a As Integer
a = Text1.Text
Do While a > 0
p = a Mod 2
a = a \ 2
n = p & n
Loop
Text2.Text = n 展开
1个回答
展开全部
12345678910111213141516171819202122Option Explicit Dim sBin As String Dim sHex As StringPrivate Sub Command1_Click() sHex = Text1 HexToBin (sHex) Text2 = 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 iEnd Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询