For each number from -128 to 127, print its 8-bit two's complement pattern.
Input
The first line has q (1 ≤ q ≤ 100). Each of the next q lines has a number from -128 to 127.
Output
One line per number: exactly 8 binary digits.
Examples
Example 1 · Input
3 5 -5 -1
Expected output
00000101 11111011 11111111
Example 2 · Input
1 0
Expected output
00000000
Hints
Hint 1
Store the number in an unsigned char: its 8 bits are the two's complement pattern.
Hint 2
Print bit i with (bits >> i) & 1, from i = 7 down to 0.
Solution
Show one correct solution (try it yourself first)
#include <stdio.h>
int main(void) {
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int n;
scanf("%d", &n);
unsigned char bits = (unsigned char)n;
for (int b = 7; b >= 0; b--) printf("%d", (bits >> b) & 1);
printf("\n");
}
return 0;
}