Visual Basic Programming Code Examples Visual Basic > API and Miscellaneous Code Examples Binary Numbers to Decimal Binary Numbers to Decimal 'This function receives a string, hopefully containing a 'binary number and returns the decimal equivalent. Function BinToDec(ByVal BinValue As String) As Byte 'Dimension some variables. Dim lngValue As Byte Dim x As Long Dim k As Long k = Len(BinValue) For x = k To 1 Step -1 If Mid$(BinValue, x, 1) = "1" Then If k - x > 30 Then lngValue = lngValue Or -2147483648# 'avoid overflow Else lngValue = lngValue + 2 ^ (k - x) End If End If Next x BinToDec = lngValue End Function