#include <stdio.h>
#include <string.h>
void print_binary(char* out, unsigned int number, unsigned int size)
{
memset(out
, '0', sizeof(char)*size
);
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\n", 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+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCnZvaWQgcHJpbnRfYmluYXJ5KGNoYXIqIG91dCwgdW5zaWduZWQgaW50IG51bWJlciwgdW5zaWduZWQgaW50IHNpemUpCnsKCW1lbXNldChvdXQsICcwJywgc2l6ZW9mKGNoYXIpKnNpemUpOwoKCXVuc2lnbmVkIGludCBpID0gMDsKICAgIGZvciAodW5zaWduZWQgaW50IG4gPSBudW1iZXI7IG47IG4gPSBuID4+IDEpIHsKICAgIAlpZiAoaSA8IHNpemUpIHsKICAgICAgICAgb3V0W3NpemUgLSBpIC0xXSA9ICcwJysobiYxKTsKICAgIAl9CiAgICAJaSsrOwogICAgfQogICAgb3V0W3NpemVdID0gJ1wwJzsKICAgIAogICAgLy9wdXRjKCchJywgb3V0KTsKICAgIC8vcHJpbnRmKCIlc1xuIiwgb3V0KTsKICAgIC8vcmV0dXJuIG91dDsKfQoKaW50IG1haW4odm9pZCkgewoJY2hhciBmb3VydHl0d29bOF07CglwcmludF9iaW5hcnkoZm91cnR5dHdvLCA0MiwgOCk7CglwcmludGYoIiVzXG4iLCBmb3VydHl0d28pOwoJCgljaGFyIHplcm9bMTZdOwoJcHJpbnRfYmluYXJ5KHplcm8sIDAsIDE2KTsKCXByaW50ZigiJXNcbiIsIHplcm8pOwoJCgljaGFyIG1pbnVzZm91cnR5dHdvWzQ4XTsKCXByaW50X2JpbmFyeShtaW51c2ZvdXJ0eXR3bywgLTEyLCA0OCk7CglwcmludGYoIiVzXG4iLCBtaW51c2ZvdXJ0eXR3byk7CglyZXR1cm4gMDsKfQo=