Created
June 18, 2020 04:32
-
-
Save wudi/8434cf211cdfcd0ed21f03946aca819e to your computer and use it in GitHub Desktop.
print in binary format
This file contains hidden or 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
#define SHOW_BITS(a) ({ \ | |
printf("Variable `%s`: ", #a);\ | |
show_bits(&a, sizeof(a));\ | |
}) | |
void show_uchar(unsigned char a) | |
{ | |
for(int i = 7; i >= 0; i-= 1) | |
printf("%d", ((a >> i) & 1)); | |
} | |
void show_bits(void* a, size_t s) | |
{ | |
unsigned char* p = (unsigned char*) a; | |
for(int i = s-1; i >= 0 ; i -= 1) { | |
show_uchar(p[i]); | |
printf(" "); | |
} | |
printf("\n"); | |
} | |
float float_var = 9.4; | |
SHOW_BITS(float_var); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment