0% found this document useful (0 votes)
58 views2 pages

Decimal 2 Biner

This document describes two functions for converting between binary and decimal numbers. The first function, Bin_To_Dec, takes a binary string as input and returns the decimal equivalent. It loops through each digit of the binary number, raising 2 to the power of the position and adding to the total decimal value. The second function, ToBinary, takes a decimal number as input and returns the equivalent binary string. It uses modulo and division to extract each binary digit and build the output string from right to left.

Uploaded by

Hotland Sitorus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views2 pages

Decimal 2 Biner

This document describes two functions for converting between binary and decimal numbers. The first function, Bin_To_Dec, takes a binary string as input and returns the decimal equivalent. It loops through each digit of the binary number, raising 2 to the power of the position and adding to the total decimal value. The second function, ToBinary, takes a decimal number as input and returns the equivalent binary string. It uses modulo and division to extract each binary digit and build the output string from right to left.

Uploaded by

Hotland Sitorus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Fungsi Konversi Biner ke Decimal

Public Function Bin_To_Dec(ByVal Bin As String) 'function to convert a binary number to decimal

Dim dec As Double = Nothing

Dim length As Integer = Len(Bin)

Dim temp As Integer = Nothing

Dim x As Integer = Nothing

For x = 1 To length

temp = Val(Mid(Bin, length, 1))

length = length - 1

If temp <> "0" Then

dec += (2 ^ (x - 1))

End If

Next

Return dec

End Function
Desimal ke Biner Konversi

Private Function ToBinary(dec As Integer) As String


Dim bin As Integer
Dim output As String
While dec <> 0
If dec Mod 2 = 0 Then
bin = 0
Else
bin = 1
End If
dec = dec \ 2
output = Convert.ToString(bin) & output
End While
If output Is Nothing Then
Return "0"
Else
Return output
End If
End Function

You might also like