'純數字轉換系統
Public Class Form1
Dim D2B As String
Dim Dec As Integer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dec = InputBox("請輸入0~255之間的任意數字")
D2B = ""
Do While Dec > 0
D2B = Dec Mod 2 & D2B
Dec = Dec \ 2
Loop
MsgBox(D2B)
End
End Sub
End Class
'將位數補齊為8位數
Public Class Form1
Dim D2B As String
Dim Dec As Integer
Dim supply As String
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dec = InputBox("請輸入0~255之間的任意數字")
D2B = ""
Do While Dec > 0
D2B = Dec Mod 2 & D2B
Dec = Dec \ 2
Loop
checkD2B(D2B)
MsgBox(D2B)
End
End Sub
Sub checkD2B(ByRef D2B As String)
'當二進位數字長度小於八位數時,將其數字補齊。
If Len(D2B) < 8 Then
For i = 1 To 8 - Len(D2B)
supply &= "0"
Next
End If
D2B = supply & D2B
End Sub
End Class
沒有留言:
張貼留言