Decimal to Binary Converter in C
This program converts decimal to binary numbers. It works for positive integers 0-127. To see how conversions between number systems work, read the post on The Decimal, Binary, Octal & Hexadecimal Number Systems
Executable - Download decimal2binary.exe
Code -
#include<stdio.h>
#include<conio.h>
/* program to convert decimal to binary
- works for positive numbers 0-127 */
int main()
{
int x, i=0;
printf("Enter the decimal number\n");
scanf("%d", &x);
int y=x;
int j=0;
/* this loop gets a count of the number of bigits/remainders */
while(x!=0)
{
i=x%2;
x=x/2;
j++;
}
x=y;
int n=0, a[n];
/* second loop feeds values of bigits to array */
while(n<j && x!=0)
{
i=x%2;
x=x/2;
a[n]=i;
n++;
}
n=0;
printf("The binary equivalent is ");
/* third loop prints the reversed array */
while(n<j)
{
printf("%d", a[j-(n+1)]);
n++;
}
getch();
return 0;
}
Categories: Programming c program convert decimal to binary, c programming question, decimal to binary, decimal to binary application, decimal to binary c program, decimal to binary converter, decimal to binary converter c program, decimal to binary converter free, decimal to binary converter in c, free decimal to binary converter download, program converters decimal to binary, program to convert decimal to binary
Keep up the knowledge as it gives life