JSFiddle - React, Tailwind, and code Playground
JavaScript
function bits(num) {
if (num === 0) return 0;
return Math.floor(Math.log(num)/Math.LN2+1);
}
var a = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768];
console.log(a.map(function(n){ return n.toString(2);}));
console.log(a.map(bits));