Converting Number in Another Base to Base10 in C#

Updated on     Kisan Patel

To convert a number in another base to base10, you need to use the static Convert.ToInt32 method as shown in below snippet:

class Program
{
    static void Main(string[] args)
    {
        string base2 = "10";
        string base8 = "112";
        string base10 = "110";
        string base16 = "11FF";
        Console.WriteLine("Convert.ToInt32(base2, 2) = " + Convert.ToInt32(base2, 2));
        Console.WriteLine("Convert.ToInt32(base8, 8) = " + Convert.ToInt32(base8, 8));
        Console.WriteLine("Convert.ToInt32(base10, 10) = " + Convert.ToInt32(base10, 10));
        Console.WriteLine("Convert.ToInt32(base16, 16) = " + Convert.ToInt32(base16, 16));
        Console.ReadKey();
    }
}

Output of the above program…

BASE-CONVERT-C-SHARP


C#

Leave a Reply