For debugging purposes I use the following definition in my C code:
#define print2binary(n) { unsigned i; for (i = 1 << 31; i > 0; i = i / 2) { (n & i)? printf("1") : printf("0"); } printf("\n"); }
It works just fine.
Now I want to be able to print larger values like unsigned long
. Therefore I tried the following:
#define print2binary(n) { unsigned long i; for (i = 1 << 63; i > 0; i = i / 2) { (n & i)? printf("1") : printf("0"); } printf("\n"); }
But this definition does not work. I do not see why it should not work. Where is my error in reasoning?