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
To find the single non-repeating element in an array where every other element appears exactly twice, which operation is applied across all elements?
Answer: XOR all elements
XOR of any number with itself is 0, so paired elements cancel out and the unique element remains.
What is the GCD of 48 and 18?
Answer: 6
Applying the Euclidean algorithm: gcd(48,18)=gcd(18,12)=gcd(12,6)=gcd(6,0)=6.
How many set bits does the number 12 (binary 1100) have?
Answer: 2
12 in binary is 1100, which has exactly two 1-bits.
What is `~0` in a 32-bit two's complement integer system?
Answer: -1
Bitwise NOT of 0 flips all 32 bits to 1, which represents -1 in two's complement encoding.
What is (7 × 8) mod 5?
Answer: 1
7 × 8 = 56, and 56 mod 5 = 1 because 56 = 11 × 5 + 1.
What does arithmetic right shift of -8 by 1 typically produce in most languages?
Answer: -4
Arithmetic right shift preserves the sign bit, so -8 >> 1 = -4, equivalent to floor division by 2.