Hello all,
you may find c code to convert decimal to binary numbers,so you are at the right place......
CODE :
#include <stdio.h> // include header file for i/o functions
int main(void) //main function definition
{
int n,i,j; //integers n=taking input for decimal number
//i and j for iterating for loop
printf("Enter Number which you want to convert into Binary Number : "); //print information on stdout
scanf("%d",&n); //read integers from stdin
for(i=sizeof(int);i>0;i--) //i=sizeof(int) typically it is 4 for gcc and 2 //for turbo c compiler
{
for(j=1;j<=8;j++)
{
printf("%u",(n&(1<<(i*8)-j))?1:0); //here i used //control statement
}
//if n AND (1<<bit number) is positive than prints 1 otherwise 0
printf(" "); //print space after printing 8 bits
}
return 0;
}
you may find c code to convert decimal to binary numbers,so you are at the right place......
CODE :
#include <stdio.h> // include header file for i/o functions
int main(void) //main function definition
{
int n,i,j; //integers n=taking input for decimal number
//i and j for iterating for loop
printf("Enter Number which you want to convert into Binary Number : "); //print information on stdout
scanf("%d",&n); //read integers from stdin
for(i=sizeof(int);i>0;i--) //i=sizeof(int) typically it is 4 for gcc and 2 //for turbo c compiler
{
for(j=1;j<=8;j++)
{
printf("%u",(n&(1<<(i*8)-j))?1:0); //here i used //control statement
}
//if n AND (1<<bit number) is positive than prints 1 otherwise 0
printf(" "); //print space after printing 8 bits
}
return 0;
}
| Output.jpg |

