The Program in C# Program to Convert Hexadecimal Number to Decimal number is given below:
using System;
namespace HexToDecimal
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, Enter a hexadecimal number here to convert them into equivalent decimal number: ");
string hexValue = Console.ReadLine();
int decValue = Convert.ToInt32(hexValue, 16);
Console.WriteLine("Okay, the equivalent decimal number is: " + decValue);
Console.ReadLine();
}
}
}
Output:
Hello Codeauri Family, Enter a hexadecimal number here to convert them into equivalent decimal number: AE
Okay, the equivalent decimal number is: 174
Pro-Tips💡
Here are the step by step execution of above program:
- Imports the “System” namespace to access the Console and Convert classes.
- Defines a namespace “HexToDecimal” containing a class “Program”.
- In the “Main” method of the “Program” class:
- Writes a message to the console asking the user to enter a hexadecimal number.
- Reads the hexadecimal number entered by the user using the “ReadLine” method of the Console class and stores it in the “hexValue” string variable.
- Converts the “hexValue” string to an integer using the “ToInt32” method of the Convert class, passing 16 as the second argument to indicate it is a hexadecimal value.
- Writes the equivalent decimal value to the console using the “WriteLine” method.
- Waits for the user to press enter using the “ReadLine” method of the Console class.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.