Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4086f3f + 9663497 commit d6612aeCopy full SHA for d6612ae
1 file changed
Recursive/BinaryEquivalent.js
@@ -0,0 +1,26 @@
1
+/*
2
+ * Problem Statement: Given a positive number `num`, find it's binary equivalent using recursion
3
+ *
4
+ * What is Binary Equivalent?
5
+ * - In binary number system, a number is represented in terms of 0s and 1s,
6
+ * for example:
7
+ * - Binary Of 2 = 10
8
+ * - Binary of 3 = 11
9
+ * - Binary of 4 = 100
10
11
+ * Reference on how to find Binary Equivalent
12
+ * - https://byjus.com/maths/decimal-to-binary/
13
14
+ */
15
+
16
+const binaryEquivalent = (num) => {
17
+ if (num === 0 || num === 1) {
18
+ return String(num)
19
+ }
20
+ return binaryEquivalent(Math.floor(num / 2)) + String(num % 2)
21
+}
22
23
+// Driver Code
24
+const num = 6
25
+const ans = binaryEquivalent(num)
26
+console.log(ans)
0 commit comments