Private Sub Form_Load()
n = Val(InputBox("请输入要转换的十进制数整数"))
m = n
x = "" :Y=""
Do While n <> 0
a = n Mod 2
n = n \ 2
x = a & x
Loop
MsgBox m & "换成二进制数是:" & x
Do While Len(X) Mod 4 <> 0
X = "0" + X
Loop
Do While Len(X) > 0
Select Case Right(X, 4)
Case "0000"
y= "0" + y
Case "0001"
y= "1" + y
Case "0010"
y = "2" + y
Case "0011"
y = "3" + y
Case "0100"
y = "4" + y
Case "0101"
y = "5" + y
Case "0110"
y = "6" + y
Case "0111"
y = "7" + y
Case "1000"
y = "8" + y
Case "1001"
y = "9" + y
Case "1010"
y = "A" + y
Case "1011"
y = "B" +y
Case "1100"
y = "C" + y
Case "1101"
y = "D" + y
Case "1110"
y = "E" + y
Case "1111"
y = "F" + y
End Select
X = Left(X, Len(X) - 4)
Loop
MsgBox m & "换成十六进制数是:" & y
End Sub
'窗体上 画两个输入框 text1 text2 粘如下代码
Private Sub Text1_Change()
Dim I As Integer
Dim S As String
Dim StrOut As String
For I = 1 To Len(Text1.Text)
S = CStr(Hex(Asc(Mid(Text1.Text, I, 1))))
If Len(S) = 1 Then S = "0" & S
StrOut = StrOut & S
Next I
Text2.Text = StrOut
End Sub
'数字 字母 符号 汉字都能整。
hex(十进制数)
拿
十进制数
除以十六就可以了
10转16:
100以内一点的10转16心算比较快。10转16用传统的计算方式可以了,就是大于15小于256的10进制数除以16为的值为十位的16进制数,其余数为个位的16进制数,没余数则个位为0。如61的16进制是3D,61除以16得3余13,3作十位数,13转成D为各位数。