Skip to content

Commit 24cbe03

Browse files
authored
Merge pull request #10 from ms10398/master
Added Decimal to BInary Conversion
2 parents 7c11bde + b9fea2c commit 24cbe03

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Conversions/DecimalToBinary.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function decimalToBinary(num) {
2+
var bin = [];
3+
while (num > 0) {
4+
bin.unshift(num % 2);
5+
num >>= 1; // basically /= 2 without remainder if any
6+
}
7+
console.log("The decimal in binary is " + bin.join(''));
8+
}
9+
10+
decimalToBinary(2);
11+
decimalToBinary(7);
12+
decimalToBinary(35);

0 commit comments

Comments
 (0)