CodeItBetter Programming Another VB Programming Blog

How to convert Binary Number to Decimal Number

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'Math - How to convert Binary Number to Decimal Number

Private Function BinaryToDecimal(ByVal sValue As String) As Long
    Dim lValue As Long, X As Long, K As Long
    K = Len(sValue)
    For X = K To 1 Step -1
        If Mid$(sValue, X, 1) = "1" Then
            If K - X > 30 Then
                lValue = lValue Or -2147483648#
            Else
                lValue = lValue + 2 ^ (K - X)
            End If
        End If
    Next X
    BinaryToDecimal = lValue
End Function
 
Private Sub Main()
    MsgBox BinaryToDecimal("101010101")
End Sub
Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.