25+ C Decimal to Hexadecimal Converters

This post contains a total of 25+ Hand-Picked C Decimal to Hexadecimal Converter Examples. All the Decimal to Hexadecimal converters are made using C Programming language.

You can use the source codes of these programs for your own personal or educational use with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Amin RJ

Made by Amin RJ. A simple C Program to convert decimal number to hexadecimal. It also displays octal output. ( Source )

#include <stdio.h>

int main() {
int dec;
scanf("%d",&dec);
printf("Octal number:%o\n",dec);
printf("Hexadecimal number:%x\n",dec);
    return 0;
}

2. By Manthan Gohel

Made by Manthan Gohel. ( Source )

#include <stdio.h>
/* Please enter a "Decimal" number*/

int main() {
    int a;
    
    scanf("%d", &a);
    
    printf("Hexa-decinal: %x", a);
    
    printf("\n\nWelcome to my first C code!\n    I know this is a very simple code\nbut if you enjoyed it then GIVE AN UPVOTE!!!               ~Thank you");
    
    return 0;
}

3. By Alexandre Correia

Made by Alexandre Correia. ( Source )

//dec to hex num 


#include <stdio.h>

int id1;

int main() 
{
    printf ("Insert Decimal Number: \n");
    scanf ("%d", &id1);
    
    printf ("Hexadecimal conversion: %x", id1);
    
    return 0;
}

4. By Karthik Paladugula

Made by Karthik Paladugula. Give the decimal number as input and the output is corresponding hexadecimal number. ( Source )

#include <stdio.h>
#include<string.h>
int main() {
    int n,i,r;
    char a[20];
    printf ("Enter the decimal number\n");
    scanf("%d",&n);
    printf("The hexadecimal number for %d is \n",n);
    for(i=0,r=0;n>0;n=n/16,++i)
    {
        r=n%16;
        if(r==0)
        a[i]='0';
        else if(r==1)
        a[i]='1';
        else if(r==2)
        a[i]='2';
        else if(r==3)
        a[i]='3';
        else if(r==4)
        a[i]='4';
        else if(r==5)
        a[i]='5';
        else if(r==6)
        a[i]='6';
        else if(r==7)
        a[i]='7';
        else if(r==8)
        a[i]='8';
        else if(r==9)
        a[i]='9';
        else if(r==10)
        a[i]='a';
        else if(r==11)
        a[i]='b';
        else if(r==12)
        a[i]='c';
        else if(r==13)
        a[i]='d';
        else if(r==14)
        a[i]='e';
        else if(r==15)
        a[i]='f';
            
    }
strrev(a);
puts(a);
    return 0;
}

5. By Anket Pratap Singh

Made by Anket Pratap Singh. The program displays the hexadecimal value of a decimal number along with its octal value. ( Source )


#include <stdio.h>
 
int main()
{
    int value;
     scanf("%d",&value);//inter the value
    printf("Decimal value is: %d\n",value);
    printf("Octal value is: %o\n",value);
    printf("Hexadecimal value is (Alphabet in small letters): %x\n",value);
    printf("Hexadecimal value is (Alphabet in capital letters): %X\n",value);   
    return 0;   
}

6. By DHARAM SINGH

Made by DHARAM SINGH. ( Source )

#include <stdio.h>

int main() {
char array[100];
int n,r,i=1;
int count=0;
scanf("%d",&n);

while(n>0)
{
    r=n%16;
    if(r<=9)
    {
        array[i]=r+48;
    }
    else
    {
        array[i]=r+55;
    }
    n=n/16;
    i++;
    count++;

}
for(i=count;i>0;i--)
{    
    printf("%c",array[i]);
 }
    return 0;
}

7. By meherDev

Made by meherDev. ( Source )

#include<stdio.h>

int main()
{
    int deci;
    
    printf("Enter any +ve decimal number\n");
    scanf("%d", &deci);
    
    
    printf("Decimal = %d\nHexadecimal = %x", deci, deci);
}

8. By sukumar chinthalapudi

Made by sukumar chinthalapudi. ( Source )

#include <stdio.h>
void convert(int,int);
int main() 
{
    int num;
    printf ("enter a positive decimal number:");
    scanf("%d",&num);
    printf ("\nbinary number::");
    convert (num,2);
    //printf ("\n");
    printf ("\noctal number::");
    convert (num,8);
  //  printf ("\n");
    printf ("\nhexadecimal::");
    convert(num,16);
  //  printf ("\n");
    return 0;
}
void convert (int num,int base)
{
    int rem=num%base;
    if(num==0)
    return ;
    convert (num/base,base);
    if(rem<10)
    printf ("%d",rem);
    else
    printf ("%c",rem-10+'A');
}

9. By Mubarak Husain

Made by Mubarak Husain. ( Source )

#include <stdio.h>
#include<string.h>

void decimal_to_hexa(int num)
{
	long  quotient, remainder;
	char z;
    long int i, j = 0;

    char hexadecimalnum[10];

    quotient = num;

  

    while (quotient != 0)

    {

        remainder = quotient % 16;

        if (remainder < 10)

            hexadecimalnum[j++] = 48 + remainder;

        else

            hexadecimalnum[j++] = 55 + remainder;

        quotient = quotient / 16;

    }

 

    printf("The Hexadecimal equivalent of %d is ",num);
    for (i = j; i >= 0; i--){
             printf("%c", hexadecimalnum[i]);
	}

			
    return;
  }


int main() {
	
	int num;
    //printf("Enter the Decimal number to be converted to Hexadecimal.");
	scanf("%d",&num);

	decimal_to_hexa(num);	
       
}

10. By srinivas srinu.

Made by srinivas srinu. ( Source )

#include <stdio.h>

int main()
{
    int n;
    printf ("enter a number digits should be range 0-9");
    scanf ("%d ",&n);
    
    

    printf("Decimal value is: %d\n",n);
    printf("\nOctal value is: %o\n",n);
    printf("\nHexadecimal value is (Alphabet in small letters): %x\n",n);
    printf("\nHexadecimal value is (Alphabet in capital letters): %X\n",n);

    return 0;
}

11. By Nova

Made by Nova. Program To Convert Decimal To Hexadecimal Number Input : Enter Any Positive Integer. ( Source )

#include<stdio.h>

void main()
{
    int a[15], num, i=0, j, temp;
    printf("\tDecimal To Hexadecimal Conversion\n");
    printf("\nEnter Any Decimal Number : ");
    scanf("%d",&num);
    printf("%d\n",num);
    temp=num;
    while(temp!=0)
    {
        a[i]=temp%16;
        temp/=16;
        i++;
    }
    printf("\nHexadecimal Form :  ");
    for(j=i-1;j>=0;j--)
    {
        switch(a[j])
        {
            case 10:
                printf("A");
                break;
            case 11:
                printf("B");
                break;
            case 12:
                printf("C");
                break;
            case 13:
                printf("D");
                break;
            case 14:
                printf("E");
                break;
            case 15:
                printf("F");
                break;
            default:
                printf("%d",a[j]);
        }
    }
}

12. By Oppong Richard

Made by Oppong Richard. ( Source )

#include <stdio.h>
#include <stdlib.h>
//simple decimal to hexdecimal converter
//developed by OPPONG RICHARD
int main() {

int input;

puts("THIS IS A SIMPLE DECIMAL TO HEXDECIMAL CONVERTER");



    puts("ENTER DECIMAL VALUE FOR CONVERSION");

    scanf("%d",&input);
    
    printf("\nDECIMAL VALUE : %d\n",input);
    printf("\nHEXDECIMAL VALUE : %#X",input);
    
    return 0;
}

13. By Peterson Co

Made by Peterson Co. ( Source )

#include<stdio.h>

#include <string.h>

int main() {

 int i,length,num, rem, number=0;
 char string[1000]={'A','B','C','D','E','F'};

scanf ("%d", &num);
char string1[num];
for (i=num;i>0; i=i/16)
{
    rem=i%16;
    if (rem>9){
    switch(rem)
    {
        case 10:string1[number]=string[0];
                break;
        case 11:string1[number]=string[1];
                break;
        case 12:string1[number]=string[2];
                break;      
        case 13:string1[number]=string[3];
                break;
        case 14:string1[number]=string[4];
                break;
        case 15:string1[number]=string[5];
                break;
        
        
    }
    }
    
    else{
        string1[number]=rem+'0';
    }
    number++;
}

length=strlen(string1);
length--;

for (i=length;i>=0;i--)
{
    printf("%c", string1[i]);
}
    return 0;
}

14. By Malek Alsset

Made by Malek Alsset. Basic C program to convert decimal to hexadecimal. ( Source )

#include<stdio.h>
void convert(int, int);
 
int main()
{
        int num;
        printf("Enter a decimal number : ");
        scanf("%d", &num);
        printf("\nBinary number: ");
        convert(num, 2);
        printf("\n");
        printf("\n");
        printf("\nHexadecimal number: ");
        convert(num, 16);
        printf("\n");
 
        return 0;
}
 
void convert (int num, int base)
{
        int rem = num%base;
 
        if(num==0)
                return;
        convert(num/base, base);
 
        if(rem < 10)
                printf("%d", rem);
        else
                printf("%c", rem-10+'A' );
}

15. By Soham Saha

Made by Soham Saha. It displays the hexadecimal and the octal value of a decimal. ( Source )

//Decimal to Octal , Hexadecimal
#include <stdio.h>

int main() {

    int Decimal;
    scanf("%d",&Decimal);
    printf("Decimal : %d \n",Decimal);
    
    //for octal :
    printf("Octal : ");
    printf("%o",Decimal);//printing the octal number
    printf("\n");
    
    //for hexadecimal :
    printf("Hexadecimal : ");
    printf("%x",Decimal);//printing the hexadecimal number
    printf("\n");
    
    return 0;
}

16. By Parmar Nilesh

Made by Parmar Nilesh. ( Source )

#include <stdio.h>

main() 
{
    int x;
    
    printf("Give the decimal number\n");
    
    scanf("%d",&x);
    
    printf("decimal number = %d\n",x);
    
    printf("Hexadecimal number = %x\n",x);
    
    printf("octal number = %o\n",x);
    
}

17. By Malek Alsset

Made by Malek Alsset. ( Source )

#include <stdio.h>

int main(void) 
        {
	long int decn,q,dn=0,m,l;
	int tmp;
        char s;
	printf("Input  a 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 hexadecimal value is : ");
         for(m=dn;m>0;m=m/100)
            {
               s=m % 100;
               printf("%c",s);
            }
    printf("\n\n");
}

18. By Binal Bharvad

Made by Binal Bharvad. ( Source )

#include<stdio.h>
int main()
{
    int decnum, a, i=0;
    char hexnum[50];
    printf("Enter any decimal number: ");
    scanf("%d", &decnum);
    while(decnum!=0)
    {
        a = decnum%16;
        if(a<10)
            a  = a +48;
        else
            a = a +55;
        hexnum[i] = a;
        i++;
        decnum = decnum/16;
    }
    printf("\nEquivalent Value in Hexadecimal = ");
    for(i=i-1; i>=0; i--)
        printf("%c", hexnum[i]);
    
    return 0;
}

19. By Er. Suraj Sahu

Made by Er. Suraj Sahu. ( Source )

//Number system... 
//Decimal to Hexadecimal converter 

#include <stdio.h>

int main() {
int n;
scanf("%d",&n);
printf("%x",n);

    return 0;
}

20. By Anmol Pandey

Made by Anmol Pandey. ( Source )

#include<stdio.h>

int main()
{
    int s[50],i=0,n,j;
    printf("enter the number ");
    scanf("%d",&n);
    while(n>16){
        s[i]=n%16;
        if(s[i]>9){
            s[i]=64+s[i]-9;
        }
        n=n/16;
        i++;
    }
    s[i]=n%16;
    if(s[i]>9){
        s[i]=64+s[i]-9;
    }
    printf("hexadecimal number is ");
   for(j=i;j>=0;j--){
      if(s[j]<64)
        printf("%d",s[j]);
      else
        printf("%c",s[j]);
    }
}
    

21. By AMAN SRIVASTAVA

Made by AMAN SRIVASTAVA. ( Source )

#include<stdio.h>
void binary (int a)
{ int i=0,rem,c[20],j;
	
	while(a>0)
	{
		rem=a%2;
		c[i]=rem;
		i++;
		a=a/2;}
		printf("decimal=");
	for(j=i-1;j>=0;j--)
	{
		printf("%d",c[j]);
	}printf("\n");
}
void octal (int b)
{
	int i=0,rem,j,a[20]; 
	while(b>0)
	{
		rem=b%8;
		a[i]=rem;
		b/=8;
		i++;
	}
	for(j=i-1;j>=0;j--)
	{
		printf("%d",a[j]);	
	}printf("\n");
}
void hexa (int c)
{
	int rem,d[20],i=0,j;
	while(c>0)
	{
		rem=c%16;
		d[i]=rem;
		i++;
		c/=16;
		
	}
	for(j=i-1;j>=0;j--)
	{	if(d[j]>9)
		switch(d[j])
		{
			case 10:
				printf("A");
			case 11:
				printf("B");
			case 12:
				printf("C");
			case 13:
				printf("D");
			case 14:
				printf("E");
			case 15:
				printf("F");				
		}else
		printf("%d",d[j]);	
	}printf("\n");	
}
main()
{
	int n;
	printf("enter the number to be converted");
	scanf("%d",&n);
	binary(n);
	octal(n);
	hexa(n);
}

22. By Sml Fox

Made by Sml Fox. ( Source )

#include <stdio.h>

int main() {
  
    long decimalnum, quotient, remainder;
    int i, j = 0;
    char hexadecimalnum[100];

    printf("Enter decimal number: ");
    scanf("%ld", &decimalnum);

    quotient = decimalnum;

    while (quotient != 0)
    {
        remainder = quotient % 16;
        if (remainder < 10)
            hexadecimalnum[j++] = 48 + remainder;
        else
            hexadecimalnum[j++] = 55 + remainder;
        quotient = quotient / 16;
    }

    // display integer into character
    for (i = j; i >= 0; i--)
        printf("%c", hexadecimalnum[i]);
    return 0;
}

23. By esaunoya

Made by Esaunoya. Takes in decimal value input by user and converts it to Hexadecimal ( Source )

#include <stdio.h>

int findMax(int decimal);
void convertDecimalToBinary(int decimal, char arr[], int max, char hexVals[]);
void printArray(char arr[], int max);

int main(void){
	char hexVals[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
	int decimal = -1;
	int max = -1;

	printf("Decimal to Hexadecimal Converter\n\n");
	
	while(decimal < 0){
		printf("Please enter a decimal number 0 or greater: ");
		scanf("%d", &decimal);
		if(decimal < 0)
			printf("\n You have entered a number less than 0.\n\n");
		
	}

	max = findMax(decimal);
	char hex[max];
	printf("\n");
	convertDecimalToBinary(decimal, hex, max, hexVals);
	printArray(hex, max);


	return 0;
}

int findMax(int decimal){
	int bitLen = 0;
	int mul = 1;
	while(decimal >= mul){
		bitLen++;
		mul*=16;
	}
	if(bitLen==0)bitLen=1;
	return bitLen;
}


void convertDecimalToBinary(int decimal, char arr[], int max, char hexVals[]){
	int temp;
	for(int i = 0; i < max; i++){
		temp = decimal%16;
		arr[(max-1)-i]=hexVals[temp];
		decimal = decimal >> 4;
	}
	return;
}

void printArray(char arr[], int max){
	for(int i = 0; i < max; i++){
		printf("%c", arr[i]);	
	}
	printf("\n\n");
	return;
}

24. By AZ-Haris

Made by AZ-Haris. ( Source )

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
     int dec;
     printf("Input Decimal Number : ");
     scanf("%d", &dec);
     printf("\nOctal = %o", dec);
     printf("\nHexadecimal = %X", dec);

    getch();
    return 0;
}

25. By fanajib5

Made by fanajib5. ( Source )

#include <stdio.h>
#include <stdlib.h>

// C++ program to convert a decimal
// number to hexadecimal number
// source = https://www.geeksforgeeks.org/program-decimal-hexadecimal-conversion/
// modified by FAIQ
int main()
{
	unsigned char n[3] = {222,255,49}; //decimal

    unsigned char hexaDeciNum[100];
    int i = 0;
    int p;

	for(p=0;p<=3;p++){
        while(n[p]!=0){
            int temp = 0;
            temp = n[p] % 16;
            if(temp < 10){
                hexaDeciNum[i] = temp + 48; }
            else{
                hexaDeciNum[i] = temp + 55; }
            n[p] = n[p]/16;
            temp = 0;
            i++;
	}}
  
	printf("Hexadecimal = %s", hexaDeciNum);
    printf("\nThe length is %d characters",strlen(hexaDeciNum));
    printf("\nHex = ");
    
	return 0;
}

26. By Mantra Jain

Made by Mantra Jain. ( Source )

#include<stdio.h>
int main()
{
    long int num_decimal , remainder , quotient ;
    int a = 1 , b , var ;
    char hexanum_decimal[ 100 ] ;
    printf( " Enter decimal number: " ) ;
    scanf( "%ld" , &num_decimal ) ;
    quotient = num_decimal ;
    while( quotient != 0 )
    {
        var = quotient % 16 ;
        if( var < 10 )
        var = var + 48 ;
        else
        var = var + 55 ;
        hexanum_decimal[ a++ ]= var ;
        quotient = quotient / 16;
    }
    printf( " The equivalent hexadecimal value of decimal number %ld is  : " , num_decimal ) ;
    for ( b = a -1 ; b > 0 ; b-- )
    printf( "%c" , hexanum_decimal[ b ] ) ;
    return 0 ;
    }