โ† 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 result of `0b1010 & 0b1100` in Python?

    Answer: 0b1000

    AND keeps only bits that are 1 in both operands: 1010 & 1100 = 1000 (decimal 8).

  2. Which expression uses the bitwise OR operator in Python?

    Answer: x | y

    The single pipe `|` is Python's bitwise OR; `||` and `or` are logical operators.

  3. What does `~0` evaluate to in Python?

    Answer: -1

    The bitwise NOT of 0 flips all bits, giving -1 in Python's two's complement integers.

  4. What is `7 ^ 7` in Python?

    Answer: 0

    XOR of any value with itself always produces 0 because every bit cancels.

  5. What is the result of `1 << 4`?

    Answer: 16

    Left-shifting 1 by 4 positions is equivalent to 2^4 = 16.

  6. What does `32 >> 2` evaluate to?

    Answer: 8

    Right-shifting 32 by 2 positions divides by 4, giving 8.

  7. Which bitwise operator would you use to check whether the 3rd bit (value 4) of integer x is set?

    Answer: x & 4

    ANDing with a mask isolates the target bit; a non-zero result means the bit is set.