Mohanapriya R Mohanapriya R
Updated date Jun 17, 2024
In this article, we will learn how to convert hexadecimal numbers to decimal in C#.
  • 1.2k
  • 0
  • 0

Converting Hexadecimal to Decimal in C#

To convert a hexadecimal number to decimal in C#, we can use the Convert.ToInt32() method, specifying base 16 as the input's base. 

  • Input Hexadecimal Number: Take the hexadecimal number as input.
  • Conversion: Use Convert.ToInt32() method to convert the hexadecimal number to decimal.
  • Output: Display the decimal equivalent of the hexadecimal number.

C# program:

using System;

class Program
{
    static void Main()
    {
        // Input hexadecimal number
        string hexNumber = "07E8";

        // Convert hexadecimal to decimal
        int decimalNumber = Convert.ToInt32(hexNumber, 16);

        // Output decimal equivalent
        Console.WriteLine($"Hexadecimal {hexNumber} is equal to Decimal {decimalNumber}");
        Console.ReadKey();
    }
}

Output:

Hexadecimal 07E8 is equal to Decimal 2024

Comments (0)

There are no comments. Be the first to comment!!!