What is the binary representation of a given integer?

Coding
Easy
Infosys
139.3K views

Candidates must explain how to convert an integer to its binary string form. It tests bitwise operations and division logic.

Why Interviewers Ask This

This question tests understanding of binary systems and bitwise operations. Interviewers want to see if candidates know how to perform manual conversion or use built-in functions effectively. It also checks handling of negative numbers and leading zeros.

How to Answer This Question

Explain repeatedly dividing the number by 2 and collecting remainders. Reverse the collected remainders to get the binary string. Alternatively, mention built-in functions like bin() in Python. Discuss handling negative numbers using two's complement if necessary.

Key Points to Cover

  • Division by 2
  • Remainder collection
  • Reversing the result
  • Built-in alternatives

Sample Answer

To get the binary representation of an integer, I can repeatedly divide the number by 2 and record the remainder at each step. Once the number becomes zero, I reverse the sequence of remainders to form the binary string.…

Common Mistakes to Avoid

  • Not reversing the remainders
  • Ignoring negative number handling
  • Incorrect loop termination

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 80 Coding questionsBrowse all 149 Infosys questions