โ† 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 `(5 & 3) | (5 ^ 3)`?

    Answer: 7

    5&3=1, 5^3=6; 1|6=7.

  2. In Python, what does the expression `x & (x - 1)` do when x is a power of 2?

    Answer: Returns 0

    For a power of 2, subtracting 1 flips the trailing bit; ANDing then clears the only set bit, yielding 0.

  3. What value does `0b1111 ^ 0b1010` produce?

    Answer: 5

    1111 ^ 1010 = 0101 = 5.

  4. What is the result of `255 >> 7`?

    Answer: 1

    255 = 0b11111111; shifting right 7 positions leaves only the leading 1, giving 1.

  5. Which expression toggles (flips) bit 0 of integer x?

    Answer: x ^ 1

    XOR with 1 flips the least significant bit: 0 becomes 1, and 1 becomes 0.

  6. What is `(-1) >> 1` in Python?

    Answer: -1

    Python uses arithmetic (sign-extending) right shift, so -1 >> 1 remains -1.

  7. What does `bin(6)` return in Python?

    Answer: '0b110'

    bin() returns a string with the '0b' prefix followed by the binary representation.