Last active
October 3, 2019 06:15
-
-
Save gustavorv86/00253f060248b287d6eb407063a02541 to your computer and use it in GitHub Desktop.
Print data type as 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
#include <stdio.h> | |
#include <stdlib.h> | |
// MACRO PRINTB | |
#define PRINTB(x) \ | |
for(int i=(sizeof(x)*8-1) ; i>=0 ; i--) { \ | |
(x & (1 << i)) ? printf("1") : printf("0") ; \ | |
if (i % 4 == 0) { printf(" "); } \ | |
} \ | |
printf("\n"); \ | |
// END MACRO PRINTB | |
int main() { | |
char c_dato = 255; | |
short s_dato = 255; | |
int i_dato = 255; | |
PRINTB(c_dato); | |
PRINTB(s_dato); | |
PRINTB(i_dato); | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment