/* ------------------------------------------------------------------ Show the internal binary representations of "int" and "float" ------------------------------------------------------------------ */ #include void printBits( void *ptr ); int main(int argc, char *argv[] ) { int a = 2; float b = 2; printf("int %d representation in bits: ", a); printBits(&a); printf("\n\n"); b = 2; printf("float %2.0f representation in bits: ", b); printBits(&b); printf("\n\n"); } /* ------------------------------------- Print bit representation ------------------------------------- */ void printBits( void *ptr ) { int x = *((int *)ptr); int i; for ( i = 31; i >= 0; i-- ) { if ( (x & (1 << i)) != 0 ) printf("1"); else printf("0"); } }