Converting strings to numbers in base : Convert « Development « VB.Net






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

1.Convert.ChangeType
2.Convert numeric string to SByte without a format provider
3.Convert numeric string to SByte with a format provider.
4.Convert.ToBase64CharArray converts 8-bit unsigned integer array to Unicode character array
5.Convert the Char array back to a Byte array
6.Convert.ToBase64String converts 8-bit unsigned integers to string encoded with base-64 digits.
7.Convert string by different base
8.Convert.ToDateTime (Object) converts object to a DateTime object.
9.Convert.ToDateTime Method (Object, IFormatProvider) converts object to DateTime using culture-specific format
10.Convert.ToDateTime(String) converts string to date and time value.
11.Convert.ToDateTime(String, IFormatProvider) converts string to date and time, using culture-specific format
12.Convert single value to decimal
13.Convert hex string to Int16
14.Convert hex string to int64
15.Convert Long to Integer
16.Convert double to Integer
17.Convert BigInteger to Integer
18.Convert decimal to Integer