Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added BinaryEquivalent file in Recursive #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
raklaptudirm merged 2 commits into TheAlgorithms:master from chiranjeev-thapliyal:master
Aug 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Recursive/BinaryEquivalent.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Problem Statement: Given a positive number `num`, find it's binary equivalent using recursion
*
* What is Binary Equivalent?
* - In binary number system, a number is represented in terms of 0s and 1s,
* for example:
* - Binary Of 2 = 10
* - Binary of 3 = 11
* - Binary of 4 = 100
*
* Reference on how to find Binary Equivalent
* - https://byjus.com/maths/decimal-to-binary/
*
*/

const binaryEquivalent = (num) => {
if (num === 0 || num === 1) {
return String(num)
}
return binaryEquivalent(Math.floor(num / 2)) + String(num % 2)
}

// Driver Code
const num = 6
const ans = binaryEquivalent(num)
console.log(ans)

AltStyle によって変換されたページ (->オリジナル) /