Created
June 3, 2014 22:05
-
-
Save reaandrew/21c0bbcc75086c72edfd to your computer and use it in GitHub Desktop.
Print bits for a long int in C
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(){ | |
printf("bitwise operations\n"); | |
unsigned long int num = 10; | |
int i; | |
for(i= (sizeof(unsigned long int)*8)-1;i>= 0; i--){ | |
char c = (num &(1LL<<i))? '1' : '0'; | |
putchar(c); | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment