Write C# Program to Convert Decimal to Hexadecimal Number

 using Newtonsoft.Json.Linq;

using System;

using System.Diagnostics;

using System.Text.RegularExpressions;

using System.Xml.Linq;

public class Program

{

    public static void Main(String[] args)

    {

        int DecimalNum, quotient;

        int i = 1, j, temp = 0;

        char[] HexadecimalNum = new char[200];

        char temp1;

        Console.WriteLine("Enter a Decimal Number :");

        DecimalNum = int.Parse(Console.ReadLine());

        quotient = DecimalNum;

        while (quotient != 0)

        {

            temp = quotient % 16;

            if (temp < 10)

                temp = temp + 48;

            else

                temp = temp + 55;

            temp1 = Convert.ToChar(temp);

            HexadecimalNum[i++] = temp1;

            quotient = quotient / 16;

        }

        Console.Write("Converted HexaDecimal Number is : ");

        for (j = i - 1; j > 0; j--)

        {

            Console.Write(HexadecimalNum[j]);

        }

        Console.ReadKey();

    }

}

Output:-

Enter a Decimal Number :

2314

Converted HexaDecimal Number is : 90A

एक टिप्पणी भेजें

0 टिप्पणियाँ