Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
10年积累的成都网站设计、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计制作后付款的网站建设流程,更有兖州免费网站建设让你可以放心的选择与我们合作。
MsgBox(DEC_to_HEX(255))
End Sub
Public Function DEC_to_HEX(ByVal Dec As Long) As String
Dim a As String
DEC_to_HEX = ""
Do While Dec 0
a = CStr(Dec Mod 16)
Select Case a
Case "10" : a = "A"
Case "11" : a = "B"
Case "12" : a = "C"
Case "13" : a = "D"
Case "14" : a = "E"
Case "15" : a = "F"
End Select
DEC_to_HEX = a DEC_to_HEX
Dec = Dec \ 16
Loop
End Function
numHex =Integer.Parse(strHex, Globalization.NumberStyles.AllowHexSpecifier)
或
numHex = Integer. Parse("H" strHex)
分类: 电脑/网络 程序设计 其他编程语言
问题描述:
我是这么遍的,但是最后一个输出是0,高手看一下是怎么回事
Module Module1
Sub Main()
Dim b, w, i, sum As Integer
Dim a As Long
Console.WriteLine("请输入一个二进制数")
a = Console.ReadLine()
Console.WriteLine("请输入这个二进制数的位数")
w = Console.ReadLine()
b = w
sum = 0
For i = b To 0
If a - (1 * 10 ^ b) = 0 Then
sum = sum + 1 * 10 ^ b
a = a - (1 * 10 ^ b)
b = b - 1
End If
Next
Console.WriteLine(sum)
Console.ReadLine()
End Sub
End Module
解析:
.NET 程序写成你这样也算厉害了,好好看看下面的代码
Sub Main()
Console.WriteLine("请输入一个二进制数")
Console.WriteLine(bin2int(Console.ReadLine()))
Console.ReadKey()
End Sub
Function bin2int(ByVal bin As String) As Integer
Dim i As Long
For i = 1 To bin.Length
bin2int = bin2int * 2 + Val(Mid(bin, i, 1))
Next i
End Function