# The pattern of bitstrings of square numbers

Here is a picture of "square numbers" from mathworld website. A plot of the first few square numbers represented as a sequence of binary bits is shown above. The top portion shows $$1^2$$ to $$255^2$$, and the bottom shows the next 510 values. (Black is for "one" bit, and while is for "zero" bit)

• Counting from the bottom from $0$, row $0$ has period two, and row $n$ when $n>0$ has period which is a divisor of $2^n$. – Thomas Andrews Apr 3 '13 at 14:30
• It's also the case that row $n$ values are symmetric around the multiples of $2^n$ - that is, the squares of $a2^n-b$ and $a2^n+b$ have the same $n$th bit, for all $a,b$ with $b<a2^n$ – Thomas Andrews Apr 3 '13 at 14:35
• Vertical periodicity: $(2^mn)^2=2^{2m}n^2=n^2<<2m,$ where $a<<b$ is a shifted to the left by b binary places (i.e. the pattern is shifted upwards). – Loki Clock Apr 3 '13 at 14:37
• I deleted my previous comment; the lengths of the rows of most significant digits are not powers of 2. – Loki Clock Apr 3 '13 at 20:26
• Has anyone tried this for other radixes? – Jack M Apr 3 '13 at 21:22

Note that each line is periodic. The bottom line alternates white and black, as even and odd numbers have even and odd squares. The next line is the leading bit of the numbers $\pmod 4$. As the squares $\pmod 4$ go $0,1,0,1$ it will always be white. The squares $\pmod {16}$ go $0,1,4,9,0,1,4,9,0,1,4,9,0,1,4,9$ so the next line up will go white, white, black, white and repeat. The next will be white, white, white, black. You can continue .