CSharp - Parsing numbers in base 2, 8, and 16

Introduction

You can use the overloaded methods from Convert to parse numbers in another base:

The second argument specifies the base. It can be any base:2, 8, 10, or 16.

Demo

using System;
class MainClass//from   w w  w .  j  a va2s.  c  om
{
   public static void Main(string[] args)
   {
         int thirty = Convert.ToInt32  ("1E", 16);    // Parse in hexadecimal
         uint five  = Convert.ToUInt32 ("101", 2);    // Parse in binary

         Console.WriteLine(thirty);
         Console.WriteLine(five);

   }
}

Result

Related Topic