The reason why you can simply sum the digits of a number to test for divisibility by 3 is because for all integers $n \ge 0$:
$$10^n \equiv 1 \pmod 3$$
To see why this is true, we know that $10^1 \equiv 1 \pmod 3$
Thus:
$$
10^n = 10*10*10 \cdots\\
\hspace{2.1cm} \equiv 1*1*1\cdots \pmod 3\\
\hspace{0.1cm} \equiv 1 \pmod 3\\
$$
From this we can see that for an integer $a_{n} a_{n-1} ...a_1$ in base 10 , $3 \mid a_{n} a_{n-1} ...a_1$ if and only if:
$$
\sum_{i=1}^{n} a_i \equiv 0 \pmod 3
$$
We can generalise this for any base, if $n$ is a digit in base $b$ such that:
$$
10_b \equiv 1 \pmod n
$$
Then for all integers $k \ge 0$:
$$
10_b^k \equiv 1 \pmod n
$$
There are divisibility rules for base 2.
For example, a binary number $a_{n} a_{n-1} ...a_1$ where $a_i$ is either $1$ or $0$, then $a_{n} a_{n-1} ...a_1$ is divisible by 3 if and only if:
$$
\sum_{i=1}^{\lfloor n/2 \rfloor} a_{2i} - \sum_{j=0}^{\lfloor n/2 \rfloor} a_{2j+1} \equiv 0 \pmod 3
$$
This means that $a_{n} a_{n-1} \cdots a_1$ is divisible by 3 if and only if the difference of the sum of the digits in the even positions and the sum of the digits in the odd positions is divisible by 3.
This applies in general as such for any base $b$ and a number $a_{n} a_{n-1} ...a_1$ in base $b$:
$$
(b+1) \mid a_{n-1} a_{n-2} ...a_1
$$
if and only if:
$$
\sum_{i=1}^{\lfloor n/2 \rfloor} a_{2i} - \sum_{j=0}^{\lfloor n/2 \rfloor} a_{2j+1} \equiv 0 \pmod {b+1}
$$
To see why this is also true, we know that:
$$
b \equiv -1 \pmod {b+1}
$$
Thus:
$$
b^2 \equiv 1 \pmod {b+1}
$$
Thus for all integers $i \ge 0$:
$$
b^{2i+1} \equiv -1 \pmod {b+1} \space and \space \space b^{2i} \equiv 1 \pmod {b+1}
$$
From this, $a_{n} a_{n-1} ...a_1$ is divisible by $b+1$ in base $b$ if an only if:
$$
a_1 + a_2 - a_3 + a_4 - \cdots + (-1)^{n-1}*a_n \equiv 0 \pmod {b+1}
$$
which is equalvalent to:
$$
\sum_{i=1}^{\lfloor n/2 \rfloor} a_{2i} - \sum_{j=0}^{\lfloor n/2 \rfloor} a_{2j+1} \equiv 0 \pmod {b+1}
$$
There might be 1 or 2 errors here (my first time using latex), feel free to point out.