fork download
  1. Imports System
  2.  
  3. Public Class Test
  4. Public Shared Sub Main()
  5. Console.WriteLine(BinaryToDecimal("1000"))
  6. Console.WriteLine(BinaryToDecimal("1111"))
  7. Console.WriteLine(BinaryToDecimal("0011011"))
  8. Console.WriteLine(BinaryToDecimal("1001011001"))
  9. End Sub
  10.  
  11. Public Shared Function BinaryToDecimal(ByVal Binary As String) As Integer
  12. Dim ReturnValue As Integer = 0
  13. Dim x As Integer = 1
  14. For i As Integer = Binary.Length - 1 To 0 Step -1
  15. If Binary.Chars(i) = "1"c Then
  16. ReturnValue += x
  17. End If
  18. x += x
  19. Next
  20. Return ReturnValue
  21. End Function
  22. End Class
Success #stdin #stdout 0.03s 24160KB
stdin
Standard input is empty
stdout
8
15
27
601