十六进制异或运算法则_【加试题】异或的数学符号为“⊕”,其运算法则相当于不带进位的二进制加法:0⊕0=0,1⊕0=1,0⊕1=1,1⊕1=0(即符号两侧数值相同时,计算结果为0;数值不同时为1)。...

这篇博客展示了如何使用Visual Basic (VB) 编程实现将十进制整数转换为二进制字符串(DtoB函数)和反之(BtoD函数)。通过实例代码,学习者可以理解整数转换的基本逻辑,并通过Do-While循环实现字符串比较。
摘要由CSDN通过智能技术生成

(2)

实现上述功能的VB程序如下。请在划线处填入合适的代码。

Private Sub Command1_Click()

Dim a As Integer, b

As Integer, c As Integer

Dim a1 As String, b1

As String

Dim lena1 As

Integer, lenb1 As Integer, i As Integer

Dim result As String

a = Val(Text1.Text)

b = Val(Text2.Text)

If a > b Then

c = a: a = b: b =

c

End If

result =

""

a1 = DtoB(a): b1 =

DtoB(b)

lena1 = Len(a1):

lenb1 = Len(b1)

i = 1

Do While i <=

lena1

If Mid(a1, lena1 -

i + 1, 1) = Mid(b1, lenb1 - i + 1, 1) Then

result =

"0" + result

Else

result =

"1" + result

End If

i = i + 1

Loop

result =________

Text3.Text =

BtoD(result)

End Sub

Public Function DtoB(x As Integer) As String

Dim remainder As

String

DtoB = ""

Do While x > 0

remainder = CStr(x

Mod 2)   '如:CStr(3

Mod 2)的值为"1"

DtoB = remainder +

DtoB

________

Loop

End Function

Public Function BtoD(x As String) As Integer

Dim i As Integer

BtoD = 0

For i = 1 To Len(x)

BtoD =________+ Val(Mid(x, i, 1))

Next i

End Function

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值