#include <stdio.h>
void print_binary(char* out, unsigned int number, unsigned int size)
{
//char out[size + 1];
unsigned int i = 0;
for (unsigned int n = number; n; n = n >> 1) {
if (i <= size) {
out[size - i -1] = '0'+(n&1);
}
i++;
}
out[size] = '\0';
//putc('!', out);
//printf("%s", out);
//return out;
}
int main(void) {
char fourtytwo[8];
print_binary(fourtytwo, 42, 8);
char zero[16];
print_binary(zero, 0, 16);
char minusfourtytwo[48];
print_binary(minusfourtytwo, -12, 48);
printf("%s\n", minusfourtytwo
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIHByaW50X2JpbmFyeShjaGFyKiBvdXQsIHVuc2lnbmVkIGludCBudW1iZXIsIHVuc2lnbmVkIGludCBzaXplKQp7CgkvL2NoYXIgb3V0W3NpemUgKyAxXTsKCW1lbXNldChvdXQsICcwJywgc2l6ZSk7CgoJdW5zaWduZWQgaW50IGkgPSAwOwogICAgZm9yICh1bnNpZ25lZCBpbnQgbiA9IG51bWJlcjsgbjsgbiA9IG4gPj4gMSkgewogICAgCWlmIChpIDw9IHNpemUpIHsKICAgICAgICAgb3V0W3NpemUgLSBpIC0xXSA9ICcwJysobiYxKTsKICAgIAl9CiAgICAJaSsrOwogICAgfQogICAgb3V0W3NpemVdID0gJ1wwJzsKICAgIAogICAgLy9wdXRjKCchJywgb3V0KTsKICAgIC8vcHJpbnRmKCIlcyIsIG91dCk7CiAgICAvL3JldHVybiBvdXQ7Cn0KCmludCBtYWluKHZvaWQpIHsKCWNoYXIgZm91cnR5dHdvWzhdOwoJcHJpbnRfYmluYXJ5KGZvdXJ0eXR3bywgNDIsIDgpOwoJcHJpbnRmKCIlc1xuIiwgZm91cnR5dHdvKTsKCQoJY2hhciB6ZXJvWzE2XTsKCXByaW50X2JpbmFyeSh6ZXJvLCAwLCAxNik7CglwcmludGYoIiVzXG4iLCB6ZXJvKTsKCQoJY2hhciBtaW51c2ZvdXJ0eXR3b1s0OF07CglwcmludF9iaW5hcnkobWludXNmb3VydHl0d28sIC0xMiwgNDgpOwoJcHJpbnRmKCIlc1xuIiwgbWludXNmb3VydHl0d28pOwoJcmV0dXJuIDA7Cn0K