Why can we see if a binary number is divisible by 3 when we look at the $1$'s position

884 Views Asked by At

Why is a binary number $z=b_n\dots b_1b_0$ divisible by $3$ iff the amount of $1$'s on the even position $b_{2n}$ minus the amount of $1$'s on odd positions $b_{2n+1}$is divisible by $3$?

So meaning $11000_b$ $(=24)$ is divisible by 3 because we have one $1$ on even and one $1$ on odd Position and $1-1=0$ is divisible by $3$.

$101_b$ $(=5)$is not divisible. Because $2-0=2$ is not divisible by $3$. What is the mathematical explanation?

2

There are 2 best solutions below

0
On BEST ANSWER

Even powers of $2$ are congruent to $1$ modulo $3$. Odd powers of $2$ are congruent to $2$ modulo $3$.* So suppose that in the binary representation of some number $k$, there are $m$ $1$'s in the even positions, and $n$ $1$'s in the odd positions. Then,

\begin{align} k & \equiv m+2n \mod 3 \\ & \equiv m+2n-3n \mod 3 \\ & \equiv m-n \mod 3 \end{align}

Therefore, in order for $k$ to be congruent to $0$ modulo $3$ (that is, divisible by $3$), $m$ and $n$ must be congruent modulo $3$. In other words, $m$ and $n$ must differ by a multiple of $3$.


*There are a few ways to see this. One of the simplest is induction: Observe that $2^0 = 1$ and $2^1 = 2$, then

\begin{align} 2^{r+2} & = 4 \times 2^r \\ & = 2^r + 3 \times 2^r \\ & \equiv 2^r \mod 3 \end{align}

0
On

This is the test - in any number base - for the number one greater than the base; that is, the number $r$ in base $n$ that is represented as $11_n$.

Since $n=r-1$, you know that $n^2$ is one more than some multiple of $r$. So the "hundreds" place gives the same value to a variation from a multiple of $r$ as the units place does. And similarly the "thousands" place digit gives the same (negative) variation as the "tens" place does, and so on. Thus the difference between the two alternating digit sums will accurately capture the variation from some multiple of $r$