Solution (source code)

= Solution

If $a$ has odd Hamming weight, then $a\cdot a=1$ and the final bit is $b$, so the probability is $1$. If $a$ has even Hamming weight, then $a\cdot a=0$ and the final bit is $1\oplus b$, so the probability is $0$. Thus
$$
\boxed{
\mathbb P(\text{last outcome}=b)=
\begin{cases}1,&|a|\text{ odd},\\0,&|a|\text{ even}.
\end{cases}}
$$