I am working on a function that takes a 64bits integer as parameter and returns a 64bits integer with all set bits at the end.
01011001 -> 00001111 // examples
00010100 -> 00000011
I first thought about the following algorithm:
nb_ones = countSetBit(x)
int64 res = 1
for i from 1 to nb_ones+1:
res |= (1 << i)
Here countSetBit is the one defined here
Is there something more straightforward ? I am working in C++