Private Sub Command1_Click()
Me.Font.Size = 50
Dim n As Byte
n = 118
Dim shang As Byte
Dim yushu(1 To 2) As Byte
Const shiliu As Byte = 16
Dim i As Byte
i = 2
shang = n \ shiliu
yushu(i) = n Mod shiliu
While shang <> 0
i = i - 1
n = shang
shang = n \ shiliu
yushu(i) = n Mod shiliu
Wend
Print yushu(1); yushu(2)
Me.Font.Size = 50
Dim n As Byte
n = 118
Dim shang As Byte
Dim yushu(1 To 2) As Byte
Const shiliu As Byte = 16
Dim i As Byte
i = 2
shang = n \ shiliu
yushu(i) = n Mod shiliu
While shang <> 0
i = i - 1
n = shang
shang = n \ shiliu
yushu(i) = n Mod shiliu
Wend
Print yushu(1); yushu(2)
End Sub
十六进制和二进制的步骤差不多呀~~
Print Hex(230)
更简单的做法 但是不理解 hex 的内部如何实现的。
Me.Font.Size = 50
Dim a As Integer
Dim b As Integer
Dim s As String
Dim yushu As Byte
a = 1230: b = 16
While a <> 0
yushu = a Mod b
s = f(yushu) & s
a = a \ b
Wend
Print s
End Sub
Private Function f(yushu As Byte) As String
If yushu <= 9 Then
f = yushu
Else
f = Chr(yushu + 55)
End If
End Function
结果 : 4CE
为什么必须要这样做呢 !~