# C# Program to Convert Decimal number to Hexadecimal

Table of contents

The Program in C# Program to Convert Decimal number to Hexadecimal is given below:

``````using System;

namespace DecimalToHexadecimalConversion
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family,enter a decimal number here to convert them into hexadecimal: ");
int decimalNumber = int.Parse(Console.ReadLine());

string hexadecimalNumber = "";
while (decimalNumber > 0)
{
int remainder = decimalNumber % 16;
if (remainder < 10)
{
hexadecimalNumber = remainder + hexadecimalNumber;
}
else
{using System;

namespace DecimalToHexadecimalConversion
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family,enter a decimal number here to convert them into hexadecimal: ");
int decimalNumber = int.Parse(Console.ReadLine());

string hexadecimalNumber = "";
while (decimalNumber > 0)
{
int remainder = decimalNumber % 16;
if (remainder < 10)
{
hexadecimalNumber = remainder + hexadecimalNumber;
}
else
{
hexadecimalNumber = (char)('A' + remainder - 10) + hexadecimalNumber;
}
decimalNumber /= 16;
}
Console.WriteLine("Okay, The hexadecimal representation: " + hexadecimalNumber);
}
}
}

hexadecimalNumber = (char)('A' + remainder - 10) + hexadecimalNumber;
}
decimalNumber /= 16;
}
Console.WriteLine("Okay, The hexadecimal representation: " + hexadecimalNumber);
}
}
}
``````

## Output:

Hello Codeauri Family,enter a decimal number here to convert them into hexadecimal:
10
Okay, The hexadecimal representation: A

## Pro-Tips💡

Here are the step by step execution of above program:

1. The program starts by using the “System” namespace.
2. The program defines a namespace called “DecimalToHexadecimalConversion”.
3. The program defines a class called “Program”.
4. The program defines the Main method, which is the entry point of the program.
5. The program writes a message to the console asking the user to enter a decimal number, and then reads the value entered by the user and stores it in a variable called “decimalNumber”.
6. The program initializes a string variable called “hexadecimalNumber” to store the hexadecimal representation of the decimal number.
7. The program uses a while loop to continuously divide the decimal number by 16 and find the remainder until the decimal number becomes 0.
8. The program checks the value of the remainder. If the remainder is less than 10, it converts the remainder to a string and adds it to the beginning of the “hexadecimalNumber” string. If the remainder is 10 or greater, it adds the corresponding hexadecimal digit (A-F) to the beginning of the “hexadecimalNumber” string.
9. The program divides the decimal number by 16 for the next iteration of the loop.
10. After the loop finishes, the program writes the hexadecimal representation of the decimal number to the console.
11. The program ends by returning 0 from the Main method.

### 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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

## Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

## C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

## C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

## C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

## C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

## C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X