5.30 · exercise

binary broadcast

Print 99 the way the machine sees it: eight binary digits, 01100011.

There is no %b in printf, so build the broadcast yourself. For each bit position from 7 down to 0, shift the value right by that many places, mask everything but the lowest bit with and, and print the surviving digit. One newline at the end.

what is checked

  • the eight binary digits on one line
  • the program exits cleanly
  • each digit is extracted with shifts and masks (lsr and and, no preformatted string)

Specification

args
stdoutprints the expected output
exitexits with the expected code
sourceuses lsr
sourceuses and
sourcecomputes the result (does not hardcode it)

Checked by running your program against expected behavior, never by matching a stored solution.

loading editor...
Open in playground