Lucas
Lucas

Reputation: 126

Formula for the total Hamming weight of the sequence of 1, 2, ..., n

This problem is fairly straightforward if log2(n) is a whole number as we can use a simply use:

n * log2(n)/2

however it miscounts when log2(n) isn't a whole number. My intuition is there should be a formula similar to this that works for all n but I'm having trouble finding it.

Upvotes: 0

Views: 46

Answers (0)

Related Questions