Bit manipulation

Asked atCienaInfosys
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Clarify integer width, signedness, and allowed operations.
  2. 02Express the required property as bits or masks.
  3. 03Use XOR for pair cancellation when applicable.
  4. 04Use shifts and masks with explicit bounds.
  5. 05Test zero, negatives, and high-bit cases.

Reference answer

Then expect these follow-ups

  • How do you isolate the lowest set bit?

    Tests: follow-up reasoning

  • Why does x AND (x minus one) clear one bit?

    Tests: correctness reasoning

Hiring now

Ciena has 130 open roles right now

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Analyst, Treasury Operations

    Gurugram

  • Executive Assistant – Thailand

    Pathum Tani

  • Commercial Management, Japan

    Tokyo

Or practice this question first

Next question