Q:

Write a program in C# Sharp to convert a decimal number to hexadecimal

0

Write a program in C# Sharp to convert a decimal number to hexadecimal

Sample Output:

Convert a number in decimal to hexadecimal:                                                                 
---------------------------------------------                                                                   
Input  any Decimal number: 1015                                                                             
The equivalent Hexadecimal Number : 3F7

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise55
{  
    public static void Main() 
        {
	int decn,q,dn=0,m,l;
	int tmp;
    int s;
		
	Console.Write("\n\n");
    Console.Write("Convert a number in decimal to hexadecimal:\n");
    Console.Write("---------------------------------------------");
    Console.Write("\n\n");		

	Console.Write("Input  any Decimal number: ");
    decn = Convert.ToInt32(Console.ReadLine());	
	q = decn;
        for(l=q;l>0;l=l/16)
               {
		     tmp = l % 16;
		           if( tmp < 10)
		           tmp =tmp + 48; 
				   else
		           tmp = tmp + 55;
                   dn=dn*100+tmp;
	           }
          Console.Write("\nThe equivalent Hexadecimal Number : ");
         for(m=dn;m>0;m=m/100)
            {
               s=m % 100;
               Console.Write("{0}",(char)s);
            }
    Console.Write("\n\n");
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now