i'm writing function print bits in c, i'm allowed use write
function. function doesn't work other numbers.
void print_bits(unsigned char octet) { int oct; int div; div = 128; oct = octet; while (!(div <= 1)) { if (div <= oct) { write(1, "1", 1); oct = oct % div; } else { write(1, "0", 1); div = div / 2; } } }
i have re-written code is there printf converter print in binary format?
void print_bits(unsigned char octet) { int z = 128, oct = octet; while (z > 0) { if (oct & z) write(1, "1", 1); else write(1, "0", 1); z >>= 1; } }