I have a large number stored in string.
let txt = '10000000000000041';
So how could I count bit presenting in it's a binary format. for example, the binary format of 9 is 1001, and no of 1's is 2.
What I did so far:
const countOne = (num) => {
let c = 0;
while (num > 0) {
num &= num - 1;
c++;
}
return c;
}
console.log(countOne(+'9'));
console.log(countOne(+'10000000000000041'));
This code is working fine, but not for large value, because Number in JavaScript cannot hold such large value, so it's giving the wrong answer.
I found similar questions but not for large value.