TITLE: A simple question about the Hamming weight of a square
QUESTION [5 upvotes]: Let we define the Hamming weight $H(n)$ of $n\in\mathbb{N}^*$ as the number of $1$s in the binary representation of $n$. Two questions:


Is it possible that $H(n^2)<H(n)$ ?
If so, is there an absolute upper bound for $H(n)-H(n^2)$?


It is interesting to point out that, quite non-trivially, the answers to the same questions for polynomials $\in\mathbb{R}[x]$, with the Hamming weigth being replaced by the number of non-zero coefficients, are yes and no, but I am inclined to believe that the situation for the Hamming weigth is radically different, due to the non-negativity of coefficients. What are your thoughts about it?

REPLY [5 votes]: Let $n_k=2^{2k-1}-2^k-1$. We have 
$$H(2^{2k-1}-2^k-1)=2k-2,$$
because we flip one of the $2k-1$ ones of $2^{2k-1}-1$ to a zero.
On the other hand
$$
n_k^2=2^{4k-2}-2^{3k}+2^{k+1}+1.
$$
Here the integer $m_k=2^{4k-2}-2^{3k}$ has Hamming weight $k-2$, so $H(n_k^2)=k$.
Therefore
$$H(n_k)-H(n_k^2)=k-2,$$
and the answers are 

Yes.
No.