Private Sub Command1_Click()
Dim a(16) As Integer, x As Integer
x = CInt(Text1.Text)
If x >= 0 Then a(16) = 0 Else a(16) = 1
x = Abs(x)
For i = 1 To 15
a(i) = x Mod 2
x = x \ 2
Next i
Text2.Text = ""
For i = 16 To 1 Step -1
Text2.Text = Text2.Text &a(i)
Next i
If a(16) = 0 Then
Text3.Text = Text2.Text
Text4.Text = Text2.Text
Exit Sub
End If
For i = 1 To 15
a(i) = 1 - a(i)
Next i
Text3.Text = a(16)
For i = 15 To 1 Step -1
Text3.Text = Text3.Text &a(i)
Next i
Text4.Text = a(16)
a(1) = a(1) + 1
i = 1
While a(i) = 2 And i <15
a(i) = 0
a(i + 1) = a(i + 1) + 1
i = i + 1
Wend
For i = 15 To 1 Step -1
Text4.Text = Text4.Text &a(i)
Next i
End Sub
Private Sub Command1_Click()a = InputBox("请输入-128~127之间的整数。", "输入", 0)
For i = 0 To 6
s = IIf(Abs(a) And 2 ^ i, "1", "0") &s
Next
s = IIf(a <0, "1", "0") &s '符号位
Print a &"的原码是" &s
For i = 2 To 8
T = T &IIf(Mid(s, i, 1) = "0", "1", "0")
Next
T = Mid(s, 1, 1) &T
Print a &"的反码是" &T
End Sub
请参考。
假设源码在Text1中,反码在Text2中,代码为:Private Sub Command1_Click()
For i = 1 To Len(Text1.Text)
Text2.Text = Mid(Text1.Text, i, 1) + Text2.Text
Next
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)