โ† All CodeSignal Technical Assessment Flashcard Decks

Bit Manipulation and Mathematical Reasoning Flashcards

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

Read the first 6 Bit Manipulation and Mathematical Reasoning flashcards as text
  1. What does the expression `n & (n-1)` evaluate to when n is a power of 2?

    Answer: 0

    A power of 2 has exactly one set bit; subtracting 1 flips all lower bits, so ANDing gives 0.

  2. How do you check if the k-th bit (0-indexed) of integer n is set?

    Answer: n & (1 << k)

    Shifting 1 left by k positions creates a mask; ANDing with n isolates that bit, giving a non-zero result if it is set.

  3. What is 5 XOR 3 in decimal?

    Answer: 6

    5 is 101 and 3 is 011 in binary; XOR gives 110, which equals 6 in decimal.

  4. What does left-shifting an integer n by 1 position (`n << 1`) effectively compute?

    Answer: n * 2

    Left-shifting by 1 appends a zero bit on the right, which doubles the value in base-2 representation.

  5. Which bit trick isolates the lowest set bit of integer n?

    Answer: n & (-n)

    The two's complement of n (-n) flips all bits and adds 1, so n & (-n) keeps only the rightmost set bit.

  6. What is the result of `n ^ n` for any integer n?

    Answer: 0

    XORing any value with itself cancels every bit, producing 0.