Skip to content

Instantly share code, notes, and snippets.

@ajaysusarla

ajaysusarla/print_bits_int.c Secret

Last active Jul 12, 2016
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
You can’t perform that action at this time.