Write a C program to convert an integer from decimal to binary , using logical bitwise operators
solution
solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
unsigned int x; | |
printf("enter any positive integer\n"); | |
fflush(stdout); | |
scanf("%d",&x); | |
//sizeof(int)=4 byte on my machine | |
for(int i=0;i<=31;i++) | |
{ | |
if(x&(0x8000>>i)){printf("%d",1);} | |
else {printf("%d",0);} | |
} | |
return 0; | |
} |
No comments:
Post a Comment