Home > Visual Basic 6 > Script VB Untuk Konversi Bilangan Desimal Ke Biner dan Biner Ke Desimal

Script VB Untuk Konversi Bilangan Desimal Ke Biner dan Biner Ke Desimal

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 :

Private Sub Command1_Click()
Dim Decimal1 As Long
Dim Binary1 As String
Dim Binary2 As String
On Error GoTo ErrEnd
Binary1 = ""
Binary2 = ""
Decimal1 = Text1.Text
Do Until Decimal1 = 0
If Deelbaar2(Decimal1) = False Then
Binary2 = Binary2 & 1
ElseIf Deelbaar2(Decimal1) = True Then
Binary2 = Binary2 & 0
End If
Decimal1 = Int(Decimal1 / 2)
Loop
For a = Len(Binary2) To 1 Step -1
Binary1 = Binary1 & Mid(Binary2, a, 1)
Next a
Text2.Text = Binary1
Exit Sub
ErrEnd:
Alert = MsgBox("Error " & Err.Number & ": " & Err.Description, vbCritical)
End Sub

Private Sub Command2_Click()
On Error GoTo ErrEnd
For a = 1 To Len(Text2.Text)
If Mid(Text2.Text, a, 1) <> "0" And Mid(Text2.Text, a, 1) <> "1" Then
MsgBox "Wrong binary number!"
Exit Sub
End If
Next a
Dim Binary1 As String
Dim Decimal1 As Long
Decimal1 = 0
Binary1 = Text2.Text
For a = 1 To Len(Binary1)
Decimal1 = Decimal1 * 2 + Mid(Binary1, a, 1)
Next a
Text1.Text = Decimal1
Exit Sub
ErrEnd:
Alert = MsgBox("Error " & Err.Number & ": " & Err.Description, vbCritical)
End Sub

Private Function Deelbaar2(Getal As Long) As Boolean
If Getal = Int(Getal / 2) * 2 Then
Deelbaar2 = True
ElseIf Getal <> Int(Getal / 2) * 2 Then
Deelbaar2 = False
End If
End Function

Download Source Code

Mirror link :


Referensi :

http://www.planet-source-code.com/vb/scripts/showcode.asp?lngWId=1&txtCodeId=50775

About these ads
  1. May 8, 2010 at 2:34 pm

    monk,,,ari aplikasi na aya teu?? kira2 mun dijadikeun TA,,katarima teu nyak,,trus alus teu nyak,,,heuheuheuheu

  2. May 12, 2010 at 5:11 pm

    gimana memanggil database access melalui field bertipe number yang di tampilkan di textbox di vb… cth select * from Tabel where field(number)='”& text1.text &”‘,…. punya salah krn dia membaca string…

  3. Lyna
    November 26, 2010 at 8:26 pm

    Mohon dibantu, sy ada tabel penilaian dengan nilai didalamnya berupa nilai selisih misal -2, 1. 0 dll, terus ada 1 tabel pembobotan, tabel pembobotan ini menunjukkan standart nilai jika selisih dari nilai penilaian -2 berarti nilai di pembobotan adalah 20,

    Bagaimana cara mengkonversikannya dengan sintax Vb,

    terimakasih

  4. April 15, 2011 at 8:46 pm

    thanks bangat broo sangat membantu bg ane untuk menyelesaikan TA

  5. June 24, 2011 at 11:23 pm

    izin sedot gan
    thanks share nya

  6. March 21, 2012 at 10:20 am

    ijin sedot gan

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 139 other followers

%d bloggers like this: