C Programming
- Print integer
- Add & subtract
- Odd & even
- Multiply & divide
- Check vowels
- Letter grade program
- Leap year program
- Sum of digits
- Prime numbers
- Sum of numbers
- Find factorial
- Fibonacci series
- Fibonacci triangle
- Number triangle
- Alphabet triangle
- Armstrong numbers
- Palindrome numbers
- Swap number
- Reverse number
- Decimal to binary
- Assembly code in C
- Matrix multiplication
- HCF & LCM
- nCr & nPr
- Print pattern
- Floyd’s triangle
- Pascal triangle
- Count digits
- Strong numbers
- Perfect numbers
- Sum of natural number
- Binary to decimal
- Decimal to octal
- Octal to decimal
- Binary to octal
- Octal to binary
- Add using pointer
- Bubble sort
- Insertion sort
- Selection sort
- Quick sort
- Binary search
- Linear search
- Largest element of array
- Smallest element of array
- Reverse Array
- Variable size & limit
- ASCII value of character
- Sum of array elements
- Number of element in array
- Merge two array
- Insert element in array
- Delete element from array
- Add two matrix
- Transpose matrix
- Print string
- Reverse string
- Delete vowels
- Sort string
- Remove spaces
- Swap string
- Random numbers
- Print date & time
- Print IP address
- Shut down computer
Convert decimal to binary using C
We can convert decimal to binary using C program. In this article we will convert a decimal number to its equivalent binary number through a C program.
We know the base of decimal number is 10 and the base of binary number is 2. Here we will perform this program assuming that the size of integer is 4 byte (32 bits). We will use bitwise operator here to make this program. So, lets see the program to convert a decimal number to its equivalent binary number.
Decimal to binary using bitwise operator in C
#include <stdio.h>
int main(){
int num, i, j;
printf("Enter a decimal number to convert : ");
scanf("%d", &num);
printf("\nBinary equivalent of %d is = \n", num);
for (i = 31; i >= 0; i--){
j = num >> i;
if (j & 1){
printf("1");
}else{
printf("0");
}
}
printf("\n");
return 0;
}
Output of this decimal to binary program:

Decimal to binary using array in C
// code here
Output of this decimal to binary program

C program to convert decimal to binary using recursion
#include <stdio.h>
#include <stdlib.h>
char *converter(int);
int main(){
int num;
char *a;
printf("Enter a number to convert : ");
scanf("%d", &num);
a = converter(num);
printf("\nBinary equivalent of %d is = %s\n", num, a);
free(a);
return 0;
}
char *converter(int k){
int x, y, i;
char *z;
i = 0;
z = (char*)malloc(32+1);
if (z == NULL)
exit(EXIT_FAILURE);
for (x = 31 ; x >= 0 ; x--){
y = k >> x;
if (y & 1){
*(z + i) = 1 + '0';
}else{
*(z + i) = 0 + '0';
}
i++;
}
*(z + i) = '\0';
return z;
}
Program output is as follows:
Enter a number to convert : 63
Binary equivalent of 63 is = 00000000000000000000000000111111
Process returned 0 (0x0) execution time : 14.774 s
Press any key to continue.
Previous page:Â Reverse number
Next page:Â Assembly code in C
Recommended for you: