Skip to content

Instantly share code, notes, and snippets.

@vpiotr
Last active July 3, 2017 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpiotr/73f379f651faf063397096711151c3e5 to your computer and use it in GitHub Desktop.
Save vpiotr/73f379f651faf063397096711151c3e5 to your computer and use it in GitHub Desktop.
/*
* Author: Piotr Likus, SpaceInSoft, 2016
* License: MIT
*/
#include <stdio.h>
// prints unsigned int in binary form
void printBits(unsigned int num)
{
const int bit_cnt = sizeof(unsigned int) * 8;
unsigned int mask = (1 << (bit_cnt - 1));
do
{
printf("%u", (num & mask) != 0?1:0);
mask >>= 1;
} while (mask > 0);
}
int main()
{
unsigned int test_value = 0xfa1b1122;
printf("test value as hex: %08x\n", test_value);
printf("test value as bits: ");
printBits(test_value);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment