15电气二班徐立立(十进制转为二进制)

时间:2023-02-13 20:58:57

打开VB软件,在command中进行编译,程序如下:

当n=23时,
Private Sub Command1_Click()
Dim n As Byte
n = 23
Const er As Byte = 2
Dim returnS As String
Dim shang As Byte
Dim yushu(1 To 5) As Byte
Dim i As Byte
i = 5
shang = n \ er
yushu(i) = n Mod er
returnS = yushu(i)
While shang <> 0
i = i - 1
n = shang
shang = n \ er
yushu(i) = n Mod er
returnS = yushu(i) & returnS
Wend

Print yushu(1); yushu(2); yushu(3); yushu(4); yushu(5)
End Sub


当n=230时,

Private Sub command1_click()
Me.Font.Size = 30
Print erjinzhi(230)
End Sub

-----------------------------------------------------------------

Private Function erjinzhi(m As Byte) As String
Dim n As Byte
n = m
Const er As Byte = 2
Dim returnS As String

Dim shang As Byte
Dim yushu(1 To 8) As Byte
Dim i As Byte
i = UBound(yushu)
shang = n \ er
yushu(i) = n Mod er
returnS = returnS & yushu(i)

While shang <> 0
i = i - 1
n = shang
shang = n \ er
yushu(i) = n Mod er
returnS = yushu(i) & returnS
Wend

erjinzhi = returnS


End Function