โ† 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 decimal value of `0b0101 | 0b1010`?

    Answer: 15

    0101 | 1010 = 1111 in binary, which equals 15 in decimal.

  2. What is `~5` in Python?

    Answer: -6

    ~n = -(n+1), so ~5 = -6.

  3. What is the result of `0xFF & 0x0F`?

    Answer: 0x0F

    0xFF & 0x0F keeps only the lower nibble: 0x0F (decimal 15).

  4. How would you set bit 2 (value 4) of variable `x` without changing other bits?

    Answer: x = x | 4

    OR with a mask sets the target bit to 1 while leaving all other bits unchanged.

  5. What is `3 ^ 5` in Python?

    Answer: 6

    3 = 011, 5 = 101; XOR gives 110 = 6.

  6. Which operation clears (sets to 0) bit 1 (value 2) of variable `x`?

    Answer: x = x & ~2

    ANDing with the complement of the mask (~2) forces the target bit to 0.

  7. What is the output of `print(bin(10 >> 1))`?

    Answer: 0b101

    10 in binary is 1010; shifting right by 1 gives 0101, which is 5, printed as 0b101.