You can ask TeX to do the computations itself in whatever radix you like (up to 36).
\documentclass{article}
\usepackage{xparse,array,booktabs}
\ExplSyntaxOn
\NewDocumentCommand{\digitsquares}{sO{c}m}
{% #1 * option for the header, #2 = alignment, #3 = radix
\IfBooleanTF { #1 }
{
\tl_set:Nn \l_tmpa_tl { \multicolumn{6}{c}{\mbox{Base ~ $#3$}} \\ \midrule }
}
{
\tl_clear:N \l_tmpa_tl
}
\int_step_inline:nnn { 0 } { \int_div_round:nn { #3 } { 2 } - 1 }
{
\tl_put_right:Nx \l_tmpa_tl
{
\int_to_Base:nn { ##1 } { #3 } ^2 & = & \int_to_Base:nn { (##1)*(##1) } { #3 } &
\int_compare:nT { ##1 + \int_div_round:nn { #3 } { 2 } < #3 }
{
\int_to_Base:nn { ##1 + \int_div_round:nn { #3 } { 2 } } { #3 }^2 & = &
\int_to_Base:nn
{
(##1 + \int_div_round:nn { #3 } { 2 })*
(##1 + \int_div_round:nn { #3 } { 2 })
} { #3 }
\exp_not:N \\
}
}
}
\begin{array}[#2]{@{} r @{} >{{}}c<{{}} @{} l @{\qquad} r @{} >{{}}c<{{}} @{} l @{}}
\l_tmpa_tl
\end{array}
}
\ExplSyntaxOff
\begin{document}
\[
\digitsquares*[t]{10} \qquad \digitsquares*[t]{7}
\]
\[
\digitsquares{16}
\]
\end{document}

The *
means that we want the header; the optional argument is for passing the alignment option to array
. The mandatory argument is the radix.
The array
preamble consists of two sets
r @{} >{{}}c<{{}} @{} l
that is: right aligned column, no space, a centered column with {}
on either side of the item (it will be the =
sign), left aligned column; in between a \qquad
separation. The leading and trailing @{}
nullify the padding on either side of the array.