Function btoh(m As String) As String '实现4位二进制转1位十六进制
Dim s As Integer, i As Integer
Dim str As String
str = "0123456789ABCDEF" '十六进制串,F表示10进制15
s = 0
For i = 1 To 4
s = s * 2 + Val(Mid(m, i, 1)) '4位二进制转10进制
Next i
btoh = Mid(str, s + 1, 1) '-----从十六进制串中取一个对应数
End Function
Private Sub Command1_Click()
Dim ans As String, s As String, ch As String, ret As String
Dim i As Integer, ascl As Integer, n As Integer
s = Text1.Text
ans = ""
For i = 1 To Len(s)
ch = Mid(s, i, 1) '从字符串中取一个字符
ascl = Asc(ch) '把字符转换成它的ascii码
ret = ""
For m = 1 To 8
n = (ascl + 1) Mod 2 'asc1+1与2取余保证按位取反
ret = n & ret '生成取反后的二进制串,如果asc1不加1,可得原码
ascl = ascl \ 2 '-----辗转相除求余法,可以去看10进制如何转成二进制
Next m
ret = Mid(ret, 4, 5) + Mid(ret, 1, 3) '循环左移三位
s1 = btoh(Mid(ret, 1, 4)) '二进制数前4位转16进制
s2 = btoh(Mid(ret, 5, 4)) '二进制数后4位转16进制
ans = ans & s1 & s2
Next i
Text2.Text = ans
End Sub
对于一个高中生来说,这题有点难为人,它涉及的进制换算过多,要看懂它并不容易。
Private Sub Command1_Click() Dim fs As Single fs = Val(InputBox("请输入成绩", "入成绩", 60)) Select Case fs Case Is < 60 MsgBox "不及格" Case 60 To 85 MsgBox "及格" Case Is > 85 MsgBox "优秀" End Select End Sub
只需执行现在现场吧