悬赏一个VB数制转换,要求2进制,10进制,16进制相互转换,详细点,急用,3天内,谢谢最好有详细的解释,麻烦各位了
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 04:33:21
悬赏一个VB数制转换,要求2进制,10进制,16进制相互转换,详细点,急用,3天内,谢谢最好有详细的解释,麻烦各位了
悬赏一个VB数制转换,要求2进制,10进制,16进制相互转换,详细点,急用,3天内,谢谢
最好有详细的解释,麻烦各位了
悬赏一个VB数制转换,要求2进制,10进制,16进制相互转换,详细点,急用,3天内,谢谢最好有详细的解释,麻烦各位了
代码:
Private Sub CMD_10to2_Click()
Dim reternstring As String, ModNum As Integer
Dim val_text1 As Long
val_text1 = Val(Text1.Text)
Do While val_text1 > 0
ModNum = val_text1 Mod 2
val_text1 = Fix(val_text1 / 2)
reternstring = Trim(Str(ModNum)) + reternstring
Loop
If Len(reternstring) < 8 Then reternstring = String(8 - Len(reternstring), "0") + reternstring
Text2.Text = reternstring
End Sub
Private Sub CMD_10to8_Click()
MsgBox "8进制数为 " & Oct(Text1.Text)
End Sub
Private Sub CMD_16to10_Click()
Dim B As Double
B = "&H" + Text1.Text
Text2.Text = B
End Sub
Private Sub CMD_16to2_Click()
Dim reternstring As String, ModNum As Integer
Dim val_text1 As Long
Dim Val_10 As Double
Dim LEN_A As Double, LEN_B As Integer
Val_10 = "&H" + Text1.Text
val_text1 = Val_10
Do While val_text1 > 0
ModNum = val_text1 Mod 2
val_text1 = Fix(val_text1 / 2)
reternstring = Trim(Str(ModNum)) + reternstring
Loop
LEN_A = Len(Text1.Text) * 4 '计算输入数据的位数用于计算输出二进制数的位数(1位输入位=4位二进制位)
LEN_B = LEN_A - Len(reternstring) '用输入位数(1位输入位=4位二进制位)计算输出二进制位数与实际二进制位数之差
If Len(reternstring) < Len(Text1.Text) * 4 Then reternstring = String(LEN_B, "0") + reternstring '不足预设位在前面补"0"
Text2.Text = reternstring + "b"
End Sub
Private Sub CMD_2to10_Click()
Dim B As Integer
Dim c
Cls
For B = 1 To Len(Text1.Text)
c = c + Mid(Text1.Text, B, 1) * 2 ^ (Len(Text1.Text) - B)
Next B
MsgBox "10进制数为 " & c
End Sub
Private Sub CMD_2to16_Click()
Dim B As Integer
Dim c
Cls
For B = 1 To Len(Text1.Text)
c = c + Mid(Text1.Text, B, 1) * 2 ^ (Len(Text1.Text) - B)
Next B
End Sub
Private Sub CMD_8to10_Click() '8to10
Dim B As Integer
B = "&o" + Text1.Text
MsgBox "10进制数为 " & B
End Sub
Private Sub CMD_8to16_Click()
Dim B As Integer
Dim c
Cls
For B = 1 To Len(Text1.Text)
c = c + Mid(Text1.Text, B, 1) * 8 ^ (Len(Text1.Text) - B)
Next B
MsgBox "16进制数为 " & Hex(c)
End Sub