mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-19 01:55:51 +08:00

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.
13 lines
275 B
JavaScript
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);
|