#include void printBits(int *x) { int i; for ( i = 8*sizeof(int)-1; i >=0; i-- ) { if ( *x & (1 << i) ) putchar('1'); else putchar('0'); } putchar('\n'); } int main(int argc, char *argv[]) { int a, *p; float b, *q; b = 2.0; // b = 00111111100000000000000000000000 !!! a = b; // C detects type change: performs type conversion to int ! printf("a = %d, b = %f\n", a, b); // Conversion took place (implicitly) printf("\nThe bits in a = "); printBits( (int *) &a ); printf("The bits in b = "); printBits( (int *) &b ); printf("\n"); /* =========================================== How to circumvent C's implicit conversion =========================================== */ p = (int *)&b; // Make p point to b a = *p; // Access b as an int typed variable ! printf("a = %d, b = %f\n", a, b); // NO conversion ! printf("\nThe bits in a = "); printBits((int *) &a); printf("The bits in b = "); printBits((int *) &b); printf("\n"); }