열렬히.뛰기

print_bits

école 42 > exam02 > exam02 : part2 > print_bits

문제

Assignment name  : print_bits
Expected files   : print_bits.c
Allowed functions: write
--------------------------------------------------------------------------------

Write a function that takes a byte, and prints it in binary WITHOUT A NEWLINE
AT THE END.

Your function must be declared as follows:

void	print_bits(unsigned char octet);

Example, if you pass 2 to print_bits, it will print "00000010"

공략법

char bit = (octet >> i & 1) + ‘0’

이후 bit을 출력.

이걸 i가 8에서 0이 될 때까지 반복.