Skip to content

Instantly share code, notes, and snippets.

@reaandrew
Created June 3, 2014 22:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reaandrew/21c0bbcc75086c72edfd to your computer and use it in GitHub Desktop.
Save reaandrew/21c0bbcc75086c72edfd to your computer and use it in GitHub Desktop.
Print bits for a long int in C
#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