### Binary2decimal & Decimal2binary...???

Posted:

**Wed Jul 03, 2013 10:16 am**I found this code that i need to work in control basic but i'm having trouble translating...:::

Any help is greatly appreciated.

Robert

.

- Code: Select all
`Binary to decimal and decimal to binary conversions:`

----------------------------------------------------

Public Function BinaryToDecimal(Binary As String) As Long

Dim n As Long

Dim s As Integer

For s = 1 To Len(Binary)

n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1)))

Next s

BinaryToDecimal = n

End Function

-----------------------------------------------------

Public Function DecimalToBinary(DecimalNum As Long) As String

Dim tmp As String

Dim n As Long

n = DecimalNum

tmp = Trim(Str(n Mod 2))

n = n \ 2

Do While n <> 0

tmp = Trim(Str(n Mod 2)) & tmp

n = n \ 2

Loop

DecimalToBinary = tmp

End Function

Any help is greatly appreciated.

Robert

.