Min One Bit Operations

Reduce an integer to zero using an operation that flips the rightmost bit differing from its left neighbor (or the LSB if all bits match). The sequence of values follows the Gray code order; the answer equals the number of 1 bits after XOR with n>>1.

Examples
Input: 3
Output: 2
Hints

Min One Bit Operations

Reduce an integer to zero using an operation that flips the rightmost bit differing from its left neighbor (or the LSB if all bits match). The sequence of values follows the Gray code order; the answer equals the number of 1 bits after XOR with n>>1.