Skip to content

Commit 07c4000

Browse files
Merge pull request #8097 from Ctrl-apk/patch-2
Created a Program to convert binary to decimal
2 parents 5f299b3 + 5e0f0cc commit 07c4000

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function DecimalToBinary(num) {
2+
3+
if (num >= 1) {
4+
DecimalToBinary(Math.floor(num / 2));
5+
}
6+
process.stdout.write((num % 2).toString());
7+
}
8+
9+
// Driver code
10+
const dec_val = 5;
11+
12+
// Calling function
13+
DecimalToBinary(dec_val);
14+
console.log(); // output 101

0 commit comments

Comments
 (0)