Anda di halaman 1dari 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

Anda mungkin juga menyukai