Example 67: Decimal to Binary Conversion

Learn how to convert a decimal number into its binary equivalent.

Problem

Write a function that takes a positive decimal integer as a parameter and prints its binary equivalent on the console. Also, check for negative input and return 0 in such a case.

Example

Input Outputin
-15 0
10 1010
45 101101

Demonstration

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.