42+ C Decimal to Binary Converter Programs

This post contains a total of 42+ C Decimal to Binary Converter Program Examples with Source Code. All these Decimal to Binary Converters are made using C Programming language.

You can use the source code of these examples with credits to the original owner.

Related Posts

C Decimal to Binary Converter Programs

1. By Jatin sharma

Made by Jatin Sharma. Decimal to Binary Program using While Loop. Source

10
1010
#include <stdio.h>

int main() {
int j,n,a[20],s=0;
scanf("%d",&n);
while(n!=1)
{
    a[s]=n%2;
    n=n/2; s++;
}
a[s]=1;
for(j=s;j>=0;j--)
printf("%d",a[j]);
    return 0;
}

2. By Jan Ram

Made by Jan Ram. Simple C Decimal to Binary converter program. Source

Enter an integer in to decimal value
11
11 in binary number system is 
00000000000000000000000000001011
#include <stdio.h>

int main() {
  int n,c,k;
  printf("Enter an integer in to decimal value \n ");
  scanf("%d",&n);
  
  printf("%d in binary number system is \n",n);
  for(c=31;c>=0;c--)
  {
     k=n>>c;
     
     if(k&1)
     printf("1");
     else
     printf("0");
  }
  printf("\n");
    return 0;
}

3. By Rishav Gupta

Made by Rishav Gupta. Source

enter decimal number
12
binary equivalent  is 1100
#include <stdio.h>

int main() {
int num,rem,i = 1,bin = 0,p,z;
printf("enter decimal number");
scanf("%d",&num);
z==num;
while(num>0){
rem = num%2;
num = num/2;
bin = bin+(rem*i);
i = i*10;
}
printf("\nbinary equivalent  is %d",bin);
    return 0;
}

4. By Anjali Keshri

Made by Anjali Keshri. Source

13
1101
#include <stdio.h>

int main() {
int n,binary=0,place=1,rem;
scanf("%d",&n);
while(n!=0)
{
    rem=n%2;
    n=n/2;
    binary=binary+rem*place;
    place=place*10;
}
printf("%d",binary);
    return 0;
}

5. By Ayush Dubey

Made by Ayush Dubey. Source

enter a number
14
14 to 1110
#include <stdio.h>

int main() 
{
    int n,r,sum=0,i=1,m;
    printf("enter a number\n");
    scanf("%d",&n);
    m=n;
    while(n>0)
    {
        r=n%2;
        n=n/2;
        sum=sum+r*i;
        i=i*10;
    }
    printf("%d to %d",m,sum);
    return 0;
}

6. By ALISHA

Made by ALISHA. C program to convert number from decimal to binary. ( Source )

Enter decimal number: 15
Binary value is: 1111
#include <stdio.h> 
int main() 
{ 
    int number,cnt,i; 
    int bin[32]; 
    printf("Enter decimal number: "); 
    scanf("%d",&number); 
    cnt=0; 
    /*initialize index to zero*/ 
    while(number>0) 
    { 
        bin[cnt]=number%2; 
        number=number/2; 
        cnt++; 
    } 
    /*print value in reverse order*/ 
    printf("Binary value is: "); 
    for(i=(cnt-1); i>=0;i--) 
        printf("%d",bin[i]); 
    return 0; 
}

7. Jully Fredy

Made by Jully Fredy. ( Source )

Enter a decimal number: 16
Step 1: 16/2,
 Remainder = 0,
 Quotient = 8
Step 2: 8/2,
 Remainder = 0,
 Quotient = 4
Step 3: 4/2,
 Remainder = 0,
 Quotient = 2
Step 4: 2/2,
 Remainder = 0,
 Quotient = 1
Step 5: 1/2,
 Remainder = 1,
 Quotient = 0
16 in decimal = 10000 in binary
/*Decimal to Binary conversion*/
#include <stdio.h>
#include <math.h>
long long convertDecimalToBinary(int n);

int main(){
    int n;
    printf("Enter a decimal number: \n");
    scanf("%d", &n);
    printf("%d in decimal = %lld in binary", n, convertDecimalToBinary(n));
    return 0;
}

long long convertDecimalToBinary(int n){
    long long binaryNumber = 0;
    int remainder, i = 1, step = 1;

    while (n!=0) {
        remainder = n%2;
        printf("Step %d: %d/2,\n Remainder = %d,\n Quotient = %d\n", step++, n, remainder, n/2);
        n /= 2;
        binaryNumber += remainder*i;
        i *= 10;
    }
    return binaryNumber;
}

8. By Siddharth Golecha

Made by Siddharth Golecha. ( Source )

Decimal Number:17
Binary Conversion: 10001
#include <stdio.h>
#include <math.h>
int main()
{
    int i,bi=0;
    scanf("%d",&i);
    printf("Decimal Number:%d\n",i);
   
    for(int j=0;i!=0;j++)
    {
        bi+=(i%2)*pow(10,j);
        i/=2;
    }
    printf("Binary Conversion: %d",bi);

   
}

9. By sasan zare

Made by sasan zare. ( Source )

Enter an integer in decimal number system : 18
in binary number system is:
0000000000000000000000000010010
#include <stdio.h>
int main()
{
  int n, c, k;

  printf("Enter an integer in decimal number system : ");
  scanf("%d", &n);

  printf("%d\nin binary number system is:\n", n);

  for (c = 30; c >= 0; c--)
  {
    k = n >> c;

    if (k & 1)
      printf("1");
    else
      printf("0");
  }

  printf("\n");

  return 0;
}

10. By Tushar

Made by Tushar. A program to convert decimal number into its equivalent binary number. ( Source )

Enter a decimal number :19
Binary equivalent : 10011

#include <stdio.h>

int main() {
int n,r,k=0;
printf("Enter a decimal number :");
scanf("%d",&n);
for(;;)
{
    r=(n%2)*pow(10,k++)+r;
    n/=2;
    if(n==0)
    break;
}
printf("\nBinary equivalent : %d",r);

    return 0;
}

11. By Sk

Made by Sk. ( Source )

Enter integer value of n: 20
Binary equivalent of 20 is 10100.
#include <stdio.h>

int binaryrec(int n);
void main() 
{ 
    int n, result ;
    printf("Enter integer value of n: ");
    scanf("%d", &n);
    printf ("%d", n);
    result=binaryrec(n);
    printf ("\nBinary equivalent of %d is %d.", n, result);

}
  int binaryrec (int n)
    {
       if(n==0)
       return 0;
       else
       return n%2 + 10*binaryrec(n/2);
    }

12. By oborot.bolta

Made by oborot.bolta. Enter your integer number in “num = “. ( Source )

Decimal 10 is same as binary 00001010
#include<stdio.h>
void equi_bits(unsigned char);
int main()
{
    unsigned char num = 10 ;
    printf("\nDecimal %d is same as binary ", num);
    equi_bits(num);
    return 0; 
} 
void equi_bits(unsigned char n)
{
  int i ; 
  unsigned char j , k ,mask ;
  for( i = 7 ; i >= 0 ; i--)
  {
     j=i;
     mask = 1 << j;
     k = n&mask ; // Masking
     k==0?printf("0"):printf("1");
  }  
}

13. By Brain & Bones

Made by Brain & Bones. ( Source )

21
0000010101
#include <stdio.h>
// converts a decimal number to binary number
// enter the decimal number
int main() {
	int input, s;
	int i = 0;
		scanf("%d", &input);
		int numbers[10] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1};
		for (s = 10; s > 0; s--) {
			if (input - numbers[i] >= 0){
			input = input - numbers[i];
			printf("1");
			}
			else{
			printf("0");
			}
			i++;
		}
	return 0;
}

14. By Yamin Mansuri

Made by Yamin Mansuri. ( Source )

Binary equivalent of 22 is  10110
#include <stdio.h>

int main() {

    int a[20],i,m,n,r;
    
    scanf("%d",&n);
    
    m=n;
    
    for(i=0;n>0;i++)
    {
        r=n%2;
        a[i]=r;
        n=n/2;
    }
    printf("Binary equivalent of %d is  ",m);
    for(i--;i>=0;i--)
    {
        printf("%d",a[i]);
    }
    return 0;
}

15. By Zakaria Elalaoui

Made by Zakaria Elalaoui. ( Source )

23
10111
#include<stdio.h>
long int dec2bin(long int dec)
{
int coef=1,rem,bin=0;
while(dec>0)
{     
    rem=dec%2;
    dec/=2;     
    bin+=rem*coef; 
    coef*=10; 
}  
return bin;
}    
    
int main() 
{
    long int dec;
    scanf("%ld",&dec);
    long int bin=dec2bin(dec);
    printf("%ld",bin);
return 0;
}  

16. By Wajeeh

Made by Wajeeh. ( Source )

Enter the number to convert: 24
Binary of Given Number is=11000
#include<stdio.h>    
#include<stdlib.h> 
 
int main(){  
int a[10],n,i;    
system ("cls");  
printf("Enter the number to convert: ");    
scanf("%d",&n);    
for(i=0;n>0;i++)    
{    
a[i]=n%2;    
n=n/2;    
}    
printf("\nBinary of Given Number is=");    
for(i=i-1;i>=0;i--)    
{    
printf("%d",a[i]);    
}    
return 0;  
}

17. By Saurabh B

Made by Saurabh B. C Program for Decimal to binary using recursion. ( Source )

25
11001

#include <stdio.h>
long int binary(int n)
{
    if(n==0)
    return 0;
    if(n==1)
    return 1;
    if(n%2==0)
    return 10*binary(n/2)+0;
    if(n%2==1)
    return 10*binary(n/2)+1;
}

int main() {
    int n;
    scanf("%i",&n);
    printf("%li",binary(n));
    return 0;
}

18. By Krishna Kumar Yadav

Made by Krishna Kumar Yadav. ( Source )

26
Binary of Number given Decimal is 1011
#include <stdio.h>
#include<string.h>
//Compiler version gcc  6.3.0
#include <math.h>
int main()
{
  int a, x,bin=0;
  scanf("%d",&a);
  while (a)
  {
    x=a%2;
    bin =bin*10+x;
    a=a/2;
  
  }
  printf ("Binary of Number given Decimal is %d",bin );
  
  return 0;
}

19. By Sahil

Made by Sahil. ( Source )

27
No in binary form: 11011 
#include<stdio.h>
int main()
{
    int decimal_num,binary =0,base=1,remainder;
    scanf("%d",&decimal_num);
    while(decimal_num>0)
    {
       remainder = decimal_num % 2;
       binary = binary + remainder * base;
       decimal_num = decimal_num / 2;
       base = base * 10;
    }
    printf("No in binary form: %d ",binary);
    return 0;
}

20. By Aman Kazi

Made by Aman Kazi. ( Source )

The decimal number is 28 
Number in binary form is 11100
#include<stdio.h>
int main()
{
int decimal,bin=0,base=1,remain,temp;

   scanf("%d",&decimal);
   temp=decimal;
   printf ("The decimal number is %d \n",decimal);
    
    while(temp>0)
    {
       remain = temp % 2;
       bin = bin + remain * base;
       temp = temp / 2;
       base = base * 10;
    }
    printf("Number in binary form is %d" ,bin);
    return 0;
}

21. By Austin Kline

Made by Austin Kline. ( Source )

enter a no.29
the binary equivalent is=11101
#include <stdio.h>

int main() {
int x,y,sum=0;
printf ("enter a no.");
scanf("%d",&x);  y=x;
for(int i=1;y!=0;i++)
{ int p=1;
  for(int j=i;j>1;j--)
    p*=10;
    sum=sum+(y%2)*p;
    y/=2;
}
printf("the binary equivalent is=%d",sum);
    return 0;
}

22. By Nossair el Katouri

Made by Nossair el Katouri. ( Source )

30
00011110
/*decimal to binary*/

#include <stdio.h>
int main()
{
    int N,i,x;    int T[8];    x=0;    i=8;
    scanf("%d",&N);
    if(N>=0)//_________________________________
    {
        i=8;
        do
        {
            T[i]=N%2;
            N=N/2;
            i--;
        }while(i>=0);
    }
    else//_____________________________________
    {
        N=-N;
        do
        {
            T[i]=N%2;
            if(T[i]==1 || x==1)
            {
                if(x==1)
                {
                    if(T[i]==1){T[i]=0;}
                    else {T[i]=1;}
                }
                x=1;
            }
            i--;
            N=N/2;
        }while(i>=1);
    }
    for(i=1;i<=8;i++)//________________________
    {
        printf ("%d",T[i]);
    }
}

23. By Naresh Metre

Made by Naresh Metre. ( Source )

Enter a decimal no.: 31
binary no.=11111
#include <stdio.h>
int main()
{
    int n, r, b=0, base=1;
    printf ("Enter a decimal no.:");
    scanf("%d", &n);
    while (n!=0)
    {
        r=n%2;
        b=b+base*r;
        base =base*10;
        n=n/2;
    }
    printf ("\n binary no.=%d", b);
    return 0;
}

24. By Swapnil More

Made by Swapnil More. This code takes a binary number and converts it to decimal. Examples: Input: 7 Output: 111. ( Source )

Enter decimal number: 32
The binary of 32 is 100000
#include <stdio.h>

int main() {
    int a,b=0,x,n,i,arr[1000];
    printf("Enter decimal number: ");
    scanf("%d",&n); // Takes input from user
    printf("%d\n",n);
    x=n; // Stores the input in another variable
    while(x!=0){
       a=x%2; // Stores the remainder of the number into the variable
       x=x/2; // Divides the number and stores the quotient
       arr[b]=a; // The remainder is stored in the array
       b++; // increments the array index
    }
    printf("The binary of %d is ",n);
    for(i=b-1;i>=0;i--){ // Whenever we divide a number to convert it into binary it gets stored in reverse in array
    
        printf("%d",arr[i]); // Prints the array which consists of binary numer
    }
    return 0;
}

25. By G Priya

Made by G Priya. ( Source )

 Function : convert decimal to binary : 
--------------------------------------

 33
 The Binary value is : 100001
#include<stdio.h>

long toBin(int);

int main()
{
    long bno;
    int dno;
    printf("\n Function : convert decimal to binary :\n");
    printf("--------------------------------------\n");    
    
    scanf("%d",&dno);
    bno = toBin(dno);
    printf("\n The Binary value is : %ld\n\n",bno);

    return 0;
}
long toBin(int dno)
{
    long bno=0,remainder,f=1;
    while(dno != 0)
    {
         remainder = dno % 2;
         bno = bno + remainder * f;
         f = f * 10;
         dno = dno / 2;
    }
    return bno;
}

26. By Sarthak Mund

Made by Sarthak Mund. ( Source )

34
00000000000000000000000000100010

#include <stdio.h>
int main() {
    int n, i, b;
    scanf("%d",&n);
    for(i=31; i>=0; i--)
    {
        b = n>>i;
        (b&1)?printf("1"):printf("0");
    }
}

27. By Kavita Bharti

Made by Kavita Bharti. ( Source )

enter the no 35
100011
#include <stdio.h>

int main()
 {
 int num,rem[100] ;
 printf("enter the no \n");
 scanf("%d",&num);
 int i=0;
 while(num!=0)
 {
     rem[i]=num%2;
     num=num/2;
     i++;
     }
     for(int j=i-1;j>=0;j--)
     printf("%d",rem[j]);
    
    return 0;
}

28. By Priyanshu Singh

Made by Priyanshu Singh. ( Source )

Enter a Decimal Number  

36
Now Decimal Number is converted int Binary Number

100100
#include<stdio.h>
int main()
{
	printf("\t\t\t\t\t\t\t\tTO CONVERT DECIMAL NUMBER INTO BINARY NUMBER");
	
	int a[50],n,i;
	printf("\nEnter a Decimal Number  \n");
	scanf("%d",&n);
	
	for(i=0;n>0;i++)
	{
		a[i]=n%2;
		n=n/2;
	}
	
	printf("\nNow Decimal Number is converted int Binary Number\n\n");
	
	
	for(i=i-1;i>=0;i--)
	{
		printf("%d",a[i]);
	}
}

29. By An IL

Made by An IL. ( Source )

37
100101
#include <stdio.h>

int binary(int d);

int main()
{
	int dec, bin;
	
	scanf("%d",&dec);
	
	bin=binary(dec);
	
	printf("%d",bin);
	
	return 0;
}

int binary(int d)
{
	if(d==1)
	{
		return 1;
	}
	else 
	{
		return(d%2 + binary(d/2)*10);
	}
}

30. By Mayukh Mitra

Made by Mayukh Mitra. Decimal to binary C program using recursion. ( Source )

38
100110
//ENTER ANY DECIMAL NUMBER TO CONVERT IT TO CORRESPONDING BINARY NUMBER.CHECK THIS OUT!!!


#include <stdio.h>
void print(int n)
{
        if(n==0)
        return;
        print(n/2);
        printf("%d",n%2);
}
int main() 
{
    int n;
    scanf("%d",&n);
    print(n);
    return 0;
}

31. By Zexu Knub

Made by Zexu Knub. ( Source )

Binary conversion of 39 is --> 1 0 0 1 1 1 


#include <stdio.h>
int main ()
{
    long num,bi;
    int i = 0;
    int ch[100];


    scanf("%ld",&num);
    

    while( num != 0)
    {
      bi = num % 2;
      
      ch[i] = bi;
      
      i++;
      
       num/=2;
       
        }


   while( i > 0 )
    {
    i--;
        printf("%d",ch[i]);
    }

       return 0;
}

32. By Rajat Sahu

Made by Rajat Sahu. ( Source )

Enter a Decimal Number: 40 
Equivalent Binary Number is: 101000
#include <stdio.h>
#include <math.h>

long func(int decimalnum)
{
    long binarynum = 0;
    int rem, temp = 1;

    while (decimalnum!=0)
    {
        rem = decimalnum%2;
        decimalnum = decimalnum / 2;
        binarynum = binarynum + rem*temp;
        temp = temp * 10;
    }
    return binarynum;
}

int main()
{
    int decimalnum;
    printf("Enter a Decimal Number: ");
    scanf("%d", &decimalnum);
    printf("Equivalent Binary Number is: %ld", func(decimalnum));
    return 0;
}

33. By Vinuthna

Made by Vinuthna. ( Source )

41
101001
#include <stdio.h>

int main() {
 int num,i;
 int a[50];
 scanf("%d",&num);
 for(i=0;num>0;i++)//decimal to binary
 {
     a[i]=num%2;
     num=num/2;
 }
 
 for(int j=i-1;j>=0;j--){
 printf("%d",a[j]);
 
 }
    return 0;
}

34. By GURURAJ KL

Made by GURURAJ KL. ( Source )

42
101010
//enter the input as only digits
// Ex : 8

#include <stdio.h>

int main() {
    int n, d, b = 1, s = 0;
    scanf("%d",&n);
    while(n != 0){
        d = n % 2;
        n = n / 2;
        s = s + d * b;
        b = b * 10;
    }
    printf("%d", s);
    return 0;
}

35. By Ankit Kaushik

Made by Ankit Kaushik. ( Source )

Enter any number for finding it's equivalent binary
43
101011
//Enter a deciaml number as a input //
// You found binary of entered number as output//


#include <stdio.h>
void dtob(int);

int main() {
int num;
printf(" Enter any number for finding it's equivalent binary\n");
scanf("%d",&num);
dtob(num);
    return 0;
}
void dtob(int n)
{
    if(n==1)
    printf("1");
    else {
    dtob(n/2);
    printf("%d",n%2);
    }
}

36. By Abhijit Kumar

Made by Abhijit Kumar. ( Source )

please enter any no to convert in binary
 binary equvalent of 44=101100
#include <stdio.h>

int main() 
{
    int no,i=1,j,a,b,bin=0,var;
    printf("please enter any no to convert in binary");
    scanf("%d",&no);
    var=no;
    while(no!=0)
    {
    a=no%2;
    no=no/2;
    bin=bin+(a*i);
    i=i*10;
    }
    printf("\n binary equvalent of %d=%d",var,bin);
	return 0;
}

37. By GAME CHANGER

Made by GAME CHANGER. Decimal to Binary C Program, enter decimal number to get binary output. ( Source )

Enter the decimal number:45
101101
#include <stdio.h>
 
void main()
{
  int B[100],j,n,i=0;

printf("\nEnter the decimal number:");
scanf("\n%d",&n);

while(n>0)
{
B[i]=n%2;
n=n/2;
i++;
}
for(j=i-1;j>=0;j--)
printf("%d",B[j]);

}

38. By jatin sharma

Made by jatin sharma. ( Source )

46
101110
#include <stdio.h>
int s=0;
int a[20];
int binary(int i)
{
    if(i!=1)
    {
        a[s]=i%2;
        i/=2; s++; binary(i);
    }
    else {
        a[s]=1;
        return 0;
    }
}
int main() {
int n,j;
scanf("%d",&n);
binary(n);
for(j=s;j>=0;j--)
printf("%d",a[j]);
    return 0;
}

39. By DHANUSH H V

Made by DHANUSH H V. Decimal to binary encoding in C with required array space. ( Source )

Enter a decimal number:
The Binary value of 47 is: 101111

#include<stdio.h>

void Binary(int decimal)
{
    int bin[256];
    int i=0;

    while (decimal > 0)
    {
        bin[i] = decimal % 2;
        decimal /= 2;
        i++;
    }

    for (int j=i-1; j>=0; j--)
    {
        printf("%d", bin[j]);
    }
    printf("\n");
}

int main()
{
    int decimal;

    printf("Enter a decimal number:\n");
    scanf("%d", &decimal);

    printf("The Binary value of %d is: ", decimal);
    Binary(decimal);
    return 0;
}

40. By Ravi Kumar

Made by Ravi Kumar. Converts decimal number which is base 10 number system 0-9 to binary which is base 2 number system 0 and 1. ( Source )

Enter any decimal number: 48
Equivalent binary value of decimal number 48: 110000
/*
_________________________________

 Enter any decimal number: 22
 
 Equivalent binary value of decimal number 22: 10110
 
*/


#include <stdio.h>

int main()
{
    long int decimalNumber, quotient;
    int binaryNumber[100], i=1, j;
    
    printf(" Enter any decimal number: ");
    scanf("%ld", &decimalNumber);
    
    quotient = decimalNumber;
    while(quotient != 0)
    {
        binaryNumber[i++] = quotient % 2;
        quotient = quotient / 2;
    }
    
    printf("\n Equivalent binary value of decimal number %ld: ", decimalNumber);
    
    if(decimalNumber == 0)
        printf("0");
        
    else
        for(j = i-1; j > 0; j--)
            printf("%d", binaryNumber[j]);
        
    return 0;
}

41. By SANDEEP. K

Made by SANDEEP. K. ( Source )

Enter a Decimal Number: 49 Equivalent Binary Number is: 110001
#include <stdio.h> 
#include <math.h>
 long decimalToBinary(int decimalnum) 
 { long binarynum = 0;
  int rem, temp = 1;
   while (decimalnum!=0) { rem = decimalnum%2;
   decimalnum = decimalnum / 2; 
   binarynum = binarynum + rem*temp; temp = temp * 10;
    }
     return binarynum; 
     } 
     int main()
      {
       int decimalnum; printf("Enter a Decimal Number: ");
      scanf("%d", &decimalnum); 
      printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnum));
       return 0; 
       }

42. By Nikhil Mohanty

Made by Nikhil Mohanty. ( Source )

enter the decimal value
50
50the binary number is 110010
#include <stdio.h>

int main() {
    int n,binary=0,base=1,rem;
    printf ("enter the decimal value\n");
    scanf("%d",&n);
    printf ("%d",n);
    while (n>0)
    {
        rem=n%2;
        binary =binary+rem*base;
        n/=2;
        base=base*10;
    }
    printf ("the binary number is %d",binary );
    return 0;
}

43. By Krypno

Made by Krypno. ( Source )

51
The Binary Equivalent is :110011
#include <stdio.h>

// Decimal to Binary Converter

int main() {
    static int n, b[100], rem, i;
    printf("This program converts Dècimal number to binary!\n");
    printf("Enter a Decimal Number: ");
    scanf("%d \n", &n);
    for (i=0;n!=0;i++){
        rem=n%2;
        n=n/2;
        b[i]=rem;
    }
    i--;
    printf("\nThe Binary Equivalent is :");
    while(i>=0){
        printf("%d", b[i]);
        i--;
    }
}