OA. free
Free
Accenture Core Computer Science Core Computer Science Medium

Given an integer x, x 1 is the right shift operator by 1 bit, and x << 1 is the left shift...

Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Given an integer x, x >> 1 is the right shift operator by 1 bit, and x << 1 is the left shift operator by 1 bit. Which of the following expressions is always equivalent to multiplying an integer x by 2 (assuming no overflow)?

Choose one option.
Show answer & explanation
Answer: B. x << 1

Left shifting by 1 bit multiplies a number by 2 because it shifts all bits one position to the left, effectively doubling the value. Right shift divides by 2, bitwise AND checks the least significant bit, and XOR flips bits—none of these operations multiply by 2.

Step-by-step Derivation:
Binary representation analysis:

  1. x >> 1 (right shift by 1): Divides x by 2. Example: 6 (binary 110) >> 1 = 3 (binary 11). This is division, not multiplication.

  2. x << 1 (left shift by 1): Multiplies x by 2. Example: 6 (binary 110) << 1 = 12 (binary 1100). 6 × 2 = 12. ✓

    • Shifting bits left by 1 position doubles the value because each bit moves to a position worth twice as much.
    • General rule: x << n = x × 2^n, so x << 1 = x × 2^1 = x × 2.
  3. x & 1 (bitwise AND with 1): Extracts the least significant bit (checks if x is odd). Example: 6 & 1 = 0, 7 & 1 = 1. This does not multiply by 2.

  4. x ^ 1 (XOR with 1): Flips the least significant bit. Example: 6 ^ 1 = 7, 5 ^ 1 = 4. This does not multiply by 2.

Therefore, the correct answer is B: x << 1.