Files
JavaScript/Conversions/DecimalToBinary.js
PatOnTheBack f37cac8508 Fixed Whitespace, Operators, and Quotes to Comply with JSLint
I modified the whitespace in the files and changed single quotes to double quotes.

I also changed some `==` and `!=` operators to `===` and `!==` to comply with JSLint.
2019-06-27 10:41:44 -04:00

13 lines
275 B
JavaScript

function decimalToBinary(num) {
var bin = [];
while (num > 0) {
bin.unshift(num % 2);
num >>= 1; // basically /= 2 without remainder if any
}
console.log("The decimal in binary is " + bin.join(""));
}
decimalToBinary(2);
decimalToBinary(7);
decimalToBinary(35);