Efficient way to count number of 1s in the binary representation of a number in O(1) if you have enough memory to play with. This is an interview question I found on an onli
The best way in javascript to do so is
function getBinaryValue(num){ return num.toString(2); } function checkOnces(binaryValue){ return binaryValue.toString().replace(/0/g, "").length; }
where binaryValue is the binary String eg: 1100