重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net补码的简单介绍

vb 十进制转换成 八进制 二进制原码 二进制补码 二进制反码 程序

VB.NET控制台程序:

成都创新互联,为您提供网站建设公司网站制作、网站营销推广、网站开发设计,对服务成都围栏护栏等多个行业拥有丰富的网站建设及推广经验。成都创新互联网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!

Module module3

Sub Main()

Dim i As Integer

Dim num As Integer = -35

Dim R As Integer = 8

Dim arr(33) As Integer

Dim len As Integer

arr = TransToR(num, R)

len = arr(0)

Console.Write(num " 转换成 " R " 进制后:" vbTab)

If (arr(1) = 1) Then

Console.Write("-")

End If

For i = len + 1 To 2 Step -1

Console.Write(arr(i))

Next

Console.WriteLine()

arr = TransToSourceCode(num)

Console.Write(num " 转换成32位二进制源码后:" vbTab)

Console.Write(arr(1))

For i = 32 To 2 Step -1

Console.Write(arr(i))

Next

Console.WriteLine()

arr = TransToReverseCode(num)

Console.Write(num " 转换成32位二进制反码后:" vbTab)

Console.Write(arr(1))

For i = 32 To 2 Step -1

Console.Write(arr(i))

Next

Console.WriteLine()

arr = TransToCompensatoryCode(num)

Console.Write(num " 转换成32位二进制补码后:" vbTab)

Console.Write(arr(1))

For i = 32 To 2 Step -1

Console.Write(arr(i))

Next

Console.WriteLine()

End Sub

'将十进制数num转换为R(2=R=9)进制数,结果存在arr数组中

'arr(0)存储长度, arr(1)存储符号位:1为负,0为正

Function TransToR(ByVal num As Integer, ByVal R As Integer) As Integer()

Dim arr(33) As Integer

arr(0) = 0 '初始长度

'设置符号位

If (num 0) Then

arr(1) = 1

Else

arr(1) = 0

End If

num = Math.Abs(num)

While num 0

arr(0) = arr(0) + 1

arr(arr(0) + 1) = num Mod R

num \= R

End While

Return arr

End Function

'将十进制数num转换为二进制原码

Function TransToSourceCode(ByVal num As Integer) As Integer()

Dim arr(33) As Integer

Dim i As Integer

arr = TransToR(num, 2)

'高位补零

For i = arr(0) + 2 To 32

arr(i) = 0

Next

arr(0) = 32

Return arr

End Function

'将十进制数num转换为二进制反码

Function TransToReverseCode(ByVal num As Integer) As Integer()

Dim arr(33) As Integer

Dim i As Integer

arr = TransToSourceCode(num)

If num = 0 Then

Return arr

End If

'除符号位外各位取反

For i = 2 To 33

arr(i) = 1 - arr(i)

Next

Return arr

End Function

'将十进制数num转换为二进制补码

Function TransToCompensatoryCode(ByVal num As Integer) As Integer()

Dim arr(33) As Integer

Dim i As Integer

Dim c As Integer = 0 '进位

arr = TransToReverseCode(num)

If num = 0 Then

Return arr

End If

'末尾加1

i = 2

arr(i) += 1

Do While True

arr(i) = c + arr(i)

c = arr(i) \ 2

arr(i) = arr(i) Mod 2

i += 1

If c 1 Then

Exit Do

End If

Loop

Return arr

End Function

End Module

vb.net的问题,求回复

Not一个数值实际上是对这个数值进行“非”运算,即转换为2进制,0变为1,1变为0,你可以这样试:

For i = 1 To 10

s = i

debug.print not (i Mod 5 )

Next

这样可以看到not (i Mod 5 )这个表达式究竟等于多少。

按照你的想法,应该这样做结果才是对的:

If Not (i Mod 5 0) Then

vb.net 的三元运算符怎么写

Private Sub Command1_Click()

x = Val(Text1.Text)

y = Val(Text2.Text)

Max = IIf(x y, x, y)

Print "Max="; Max

End Sub


当前名称:vb.net补码的简单介绍
网站网址:http://cqcxhl.com/article/doogsoi.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP