Number of ones to the left of every zero in binary representation
I am seeking the computationally fastest way to determine the total number
of ones to the left of every zero in the binary representation of a
number. That is: for every zero, count the number of ones that are to the
left of it, and then total the counts.
For example:
75 => {1, 0, 0, 1, 0, 1, 1}
{1}
{1}
{1, 1}
Total = 4
I wish to do this programmatically but my attempts are slow and feel
inefficient. Is there some clever method I might use?
No comments:
Post a Comment