I'm trying to print a number in binary with these two approaches:
Approach 1:
int input;
scanf("%d", &input);
for(int i = sizeof(int)*CHAR_BIT - 1; i >= 0; i--)
printf("%u",(input & (1<<i)) >> i);
Approach 2:
int input;
scanf("%d", &input);
for(int i = sizeof(int)*CHAR_BIT - 1; i >= 0; i--)
(input & (1<<i)) ? putchar('1') : putchar('0');
Approach 2 works fine but in Approach 1 the first "digit" that is printed is 4294967295 and I can't find the error.