Grokking the Art of Recursion for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
4. Converting Decimal to Binary
On this page

Problem Statement

Try it yourself

Problem Statement

Write a Recursive Procedure to Convert a Decimal Number to a Binary Equivalent.

Given a decimal number, we need to convert it to its binary representation, as explained in the following table:

Input(s)Output(s)Explanation
Decimal Number = 10Binary Number = 1010The decimal number 10 can be represented as 1010 in binary. Each digit in the binary representation corresponds to the powers of 2.
Decimal Number = 27Binary Number = 11011The decimal number 27 can be represented as 11011 in binary. Each digit in the binary representation corresponds to the powers of 2.
Decimal Number = 5Binary Number = 101The decimal number 5 can be represented as 101 in binary. Each digit in the binary representation corresponds to the powers of 2.

Constraints:

  • 0 <= n <= 10<sup>9</sup>

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Try it yourself