Source code berikut berguna untuk membantu konversi bilangan desimal ke biner dan juga sebaliknya, dari biner ke desimal. Mendukung sampai 2147483647 bilangan.
Buat 1 project dengan :
1 Form
2 CommandButton
2 TextBox
Source code :
01 | Private Sub Command1_Click() |
10 | If Deelbaar2(Decimal1) = False Then |
12 | ElseIf Deelbaar2(Decimal1) = True Then |
15 | Decimal1 = Int(Decimal1 / 2) |
17 | For a = Len(Binary2) To 1 Step -1 |
18 | Binary1 = Binary1 & Mid(Binary2, a, 1) |
23 | Alert = MsgBox( "Error " & Err.Number & ": " & Err.Description, vbCritical) |
26 | Private Sub Command2_Click() |
28 | For a = 1 To Len(Text2.Text) |
29 | If Mid(Text2.Text, a, 1) <> "0" And Mid(Text2.Text, a, 1) <> "1" Then |
30 | MsgBox "Wrong binary number!" |
38 | For a = 1 To Len(Binary1) |
39 | Decimal1 = Decimal1 * 2 + Mid(Binary1, a, 1) |
44 | Alert = MsgBox( "Error " & Err.Number & ": " & Err.Description, vbCritical) |
47 | Private Function Deelbaar2(Getal As Long ) As Boolean |
48 | If Getal = Int(Getal / 2) * 2 Then |
50 | ElseIf Getal <> Int(Getal / 2) * 2 Then |
Download Source Code
Mirror link :
No comments:
Post a Comment