Embercode
✕
OperatorsQuick quiz

Bit masks and popcount in Python

8 questions. Covers Popcount and n & (n - 1) in Python.

Questions 1 to 5 of 8

  1. 1. What does this line print? ``python print(format(6 | 1, 'b')) ``
  2. 2. Write the Python expression that clears bit 3 of an int named flags, using a mask built with 1 << 3. Write it exactly as you would in code.

    Type your answer.

  3. 3. What does this program print? ``python m = 0b1011 m = m & ~(1 << 0) print(m) ``
  4. 4. Which expression is true only when n is a power of two?
  5. 5. What does this line print? ``python print(~(1 << 2)) ``

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.