网站建设资讯

NEWS

网站建设资讯

vb.net进制大全 进制转换vb程序设计

VB.NET,八/十六进制转十进制的函数

VB.Net自带函数:

创新互联是一家集网站建设,吐鲁番企业网站建设,吐鲁番品牌网站建设,网站定制,吐鲁番网站建设报价,网络营销,网络优化,吐鲁番网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

十进制转八进制:Oct(num)

十六进制转八进制:oct("H" num)

十进制转十六进制:hex(num)

八进制转十六进制:hex("O" num)

十六进制转换为十进制:CLng("H" num)

vb.net 中2、8、10、16进制转换代码怎么写

Option Explicit

Dim Jz As Integer, K As Boolean

Private Sub Command1_Click()

Pic.Cls

If K Then Jz = Val(Qtjz.Text)

If Pd(Text1.Text, Jz) Then Pic.Print "选择的进制与数不符": Exit Sub

If Jz = 0 Then Pic.Print "请先输入进制" Else Pic.Print Zh(Text1.Text, Jz)

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub Option1_Click(Index As Integer)

K = False

Select Case Index

Case 0

Jz = 2

Case 1

Jz = 8

Case 2

Jz = 10

Case 3

Jz = 16

Case 4

K = True

Qtjz.Text = ""

Qtjz.SetFocus

End Select

If Index 4 Then Command1.SetFocus

End Sub

Private Sub Qtjz_Click()

Qtjz.Text = ""

End Sub

Private Sub Text1_Click()

Text1.Text = ""

End Sub

Private Function Zh(a As String, b As Integer) As Integer

Dim c As String, i, d As Integer

a = LCase(a)

For i = 1 To Len(a)

c = Mid(a, Len(a) + 1 - i, 1)

If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)

Zh = Zh + d * b ^ (i - 1)

Next i

End Function

Private Function Pd(a As String, b As Integer) As Boolean

Dim c As String, i, d As Integer

Pd = False

For i = 1 To Len(a)

c = Mid(a, Len(a) + 1 - i, 1)

If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)

If d b - 1 Then Pd = True: Exit Function

Next i

End Function

用VB.NET将二进制数转换为十进制数

分类: 电脑/网络 程序设计 其他编程语言

问题描述:

我是这么遍的,但是最后一个输出是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

vb.net 二进制比较

通过and判断

a: 00000100 a: 00000010

and b: 00000010 and b: 00000110

00000000 00000010

结果: 假 真

Qbasic代码(Basic代码是怎样的,我忘记了,很少用,你修改一下,应该可以再VB。NET运行):

a=4 '将二进制转换为十进制

b=2

c=6

if a and b then

print "a,b有同一个1"

else

print "a,b无同一个1"

end if

if b and c then

print "b,c有同一个1"

else

print "b,c无同一个1"

end if

end '不喜欢end就却掉吧


当前文章:vb.net进制大全 进制转换vb程序设计
网站路径:http://njwzjz.com/article/hgoioi.html