Convert Decimal number to Hexadecimal number

Decimal number to Hexadecimal number

Convert decimal number to hexadecimal number

We started with the short description of Hexadecimal and Decimal number-
Hexadecimal number system: It is base 16 number system which uses the digits from 0 to 9 and A, B, C, D, E, F. Used by computers to easily represent binary numbers.

Decimal number system: It is base 10 number system which uses the digits from 0 to 9. Used by humans.

#include <stdio.h>
#include<conio.h>
void main() 
        {
    long int decn,rmd,q,dn=0,m,l;
    int i=1,j,tmp;
        char s;
printf("\n\t\t\t...Welcome To EduNews.Tech... ");

       printf("\n\nConvert Decimal to Hexadecimal:\n ");
    

    printf("Input  any Decimal number: ");
    scanf("%ld",&decn);
    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;
            }
          printf("\nThe equivalent Hexadecimal Number : ");
         for(m=dn;m>0;m=m/100)
            {
               s=m % 100;
               printf("%c",s);
            }
    printf("\n\n");
printf("\n\n\n\t\t\tThankyou for Joining Us !");
    printf("\n\t\t\t!Regards EduNews !");

getch();
}

Program Output:

decimal to hexadecimal

I hope this post helps you to understand the program “Convert Decimal number to Hexadecimal number” and its implementation in C programming language.

Keep coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *