Last active
July 3, 2017 07:36
-
-
Save vpiotr/73f379f651faf063397096711151c3e5 to your computer and use it in GitHub Desktop.
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
/* | |
* 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