Assume that I have an ordinary number in Decmical base, now what I want to know is determining whether it has an even number of 1's in a binary base or not.and yet again I should emphasize the fact that I do not want the exact number of 1's in the binary base,just knowing if the number of 1's is even or odd.(by the way if you find a way to determine the exact number of 1's that should work as well)
Thanks in advance.
I'm new to English math so I apologize for any mistakes in the typing.(tried to be as clear as possible though :D)
Please feel free to edit the question and the tags if you wish.
We can define a recursive function that will return $0$ for an even number of binary $1$s and $1$ for an odd number of binary $1$s using these facts:
$2k$ has the same number of binary $1$s as $k$ has ($2k$ is obtained from $k$ by appending a $0$ to the binary representation of $k$).
$2k+1$ has one more binary $1$ than $k$ has ($2k+1$ is obtained from $k$ by appending a $1$ to the binary representation of $k$).
Our function can then be $f(0)=0$; $f(2k)=f(k)$; and $f(2k+1)=1-f(k)$. Then $f$ will return $0$ for an even number of binary ones, and $1$ for an odd number of binary $1$s.