How to print the bits of an integer in 16 bit format with JavaScript

1 Answer

0 votes
const num = 5668;
 
console.log(("0000000000000000" + num.toString(2)).substr(-16));
 
console.log(num.toString(2));

 
 
/*
run:
 
0001011000100100
1011000100100
 
*/

 



answered Jan 11, 2023 by avibootz
edited Apr 6, 2024 by avibootz

Related questions

1 answer 125 views
1 answer 112 views
1 answer 149 views
2 answers 142 views
1 answer 117 views
1 answer 100 views
...