โ† All PCEP Flashcard Decks

Bitwise Operations Flashcards

7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Bitwise Operations flashcards as text
  1. What is the operator precedence: does `&` bind tighter than `|` in Python?

    Answer: Yes, & has higher precedence than |

    In Python, & has higher precedence than ^, which has higher precedence than |.

  2. What is `12 & 10`?

    Answer: 8

    12=1100, 10=1010; AND gives 1000=8.

  3. How many bits does Python's left-shift operator `<<` add to the right of the value?

    Answer: As many as the shift amount

    `x << n` appends n zero bits to the right of x's binary representation.

  4. What is the result of `0 | 255`?

    Answer: 255

    OR with 0 leaves every bit of the second operand unchanged, so the result is 255.

  5. What is `~(-1)` in Python?

    Answer: 0

    ~n = -(n+1), so ~(-1) = -(-1+1) = 0.

  6. Which Python built-in function converts an integer to its hexadecimal string representation?

    Answer: hex()

    hex() returns a string like '0xff'; it is commonly paired with bitwise operations for readability.

  7. What is the result of `(3 << 2) & 0b111111`?

    Answer: 12

    3 << 2 = 12 = 0b001100; 0b001100 & 0b111111 = 0b001100 = 12.