Binary To Decimal

This algorithm converts binary numbers to decimal numbers.



									Public Shared Function BinaryToDecimal(bin As String) As Integer
	Dim binLength As Integer = bin.Length
	Dim dec As Double = 0

	For i As Integer = 0 To binLength - 1
		dec += (CByte(AscW(bin(i))) - 48) * Math.Pow(2, ((binLength - i) - 1))
	Next

	Return CInt(Math.Truncate(dec))
End Function
								


Example

									Dim data = "10111101011011010111110"
Dim value = BinaryToDecimal(data)
								


Output

									6207166