Public Class 進位轉換
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'2 進位轉 10 進位 16 進位
Dim tmpnum As Object = 0
For i = Len(TextBox2.Text) To 1 Step -1
tmpnum = tmpnum + Val(Mid(TextBox2.Text, i, 1)) * 2 ^ (Len(TextBox2.Text) - i) '階乘
Next
TextBox1.Text = CStr(tmpnum)
TextBox3.Text = Hex(TextBox1.Text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'10 進位轉 16 進位 補0
Dim x As Long = TextBox1.Text
Dim x1, x2 As Long
TextBox3.Text = UCase(Convert.ToString(x, 16))
x1 = Len(TextBox3.Text) '取得總數
x2 = x1 Mod 2 '取得餘數
If x2 = 1 Then '如果餘數 為1 就捕0
TextBox3.Text = "0" & TextBox3.Text
End If
'=================================================
'10進位轉 2 進位 補 0
Dim y, y1 As Object
y = Convert.ToString(x, 2)
y1 = y Mod 1 '補2進位的0
If y1 = 0 Then
TextBox2.Text = "0" & y
Else
TextBox2.Text = y
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim getcode
getcode = TextBox3.Text
Select Case getcode
Case UCase("d5")
MsgBox("AAD")
Case Else
MsgBox("nothing")
End Select
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'16 轉 10進位
Dim x, x1
x = "&H" + TextBox3.Text
x1 = CLng(x)
TextBox1.Text = x1
'=================================================
'10進位轉 2 進位
Dim y, y1 As Object
y = Convert.ToString(x1, 2)
y1 = y Mod 1 '補2進位的0
If y1 = 0 Then
TextBox2.Text = "0" & y
Else
TextBox2.Text = y
End If
End Sub
End Class
請先 登入 以發表留言。