Converting strings to numbers in base
Module Example
Public Sub Main()
Dim bases() As Integer = { 2, 8, 16}
Dim values() As String = { "FF", "8F", "01", "1C","18A" }
For Each base As Integer In bases
Console.WriteLine("Converting strings in base {0}:", base)
For Each value As String In values
Console.Write(" '{0,-5} --> ", value + "'")
Try
Console.WriteLine(Convert.ToSByte(value, base))
Catch e As FormatException
Console.WriteLine("Bad Format")
Catch e As OverflowException
Console.WriteLine("Out of Range")
End Try
Next
Next
End Sub
End Module
Related examples in the same category