Skip to content

Instantly share code, notes, and snippets.

@ajaysusarla
Last active July 12, 2016 11:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Print bits - Signed Integer
void print_bits(int num)
{
size_t bits = sizeof(num) * 8;
int max = 1 << (bits - 1);
int i;
for (i = 0; i < bits; i++) {
printf("%u", (num & max) ? 1 : 0);
num = num << 1;
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment