How to convert decimal number to binary in JavaScript

1 Answer

0 votes
function dec2bin(dec) {
	return (dec >>> 0).toString(2);
}
   
console.log(dec2bin(10));

console.log(dec2bin(30));




/*
run:
   
"1010"
"11110"
   
*/
 

 



answered Jul 23, 2016 by avibootz
edited Jan 11, 2023 by avibootz

Related questions

1 answer 154 views
1 answer 132 views
1 answer 135 views
2 answers 177 views
3 answers 123 views
3 answers 133 views
...