Pattern for all the binary chains divisible by 5 For instance, $x = 101$ is divisible by $5$ because it is the integer 5. Same thing for $x=1111$ is also divisible by 5 as it is the integer 15. However, $x=1100$ is not divisible by $5$ as it is the integer 12.
Is there a pattern the recognise the binary chains divisible by 5?
 A: For example, for $1000$ decimal, represent it as $1111101000$. In base $4$, this is $33220$ (just group pairs of digits together; if there were an odd number of digits then add a $0$ at the front).
Then $3+2+0$ (the sum of the odd-position digits) and $3+2$ (the sum of the even-position digits) are equal, so the number is divisible by 5. This works in general in base $b$ if we are testing for divisibility by $b+1$. To see that, write
$$n = \sum_{i=0}^k a_ib^i,$$
where $0\le a_i < b$; then
$$(b+1)n = \sum_{i=0}^k a_ib^{i+1} + \sum_{i=0}^k a_ib^i
= \sum_{i=1}^{k+1}a_{i-1}b^i + \sum_{i=0}^k a_ib^i
= a_0b^0 + \sum_{i=1}^{k-1} (a_{i-1} + a_i)b^i + a_kb^{k+1}.$$
From this it is easy to see that the sum of the odd-position digits and the sum of the even-position digits are equal.
A: I use a similar approach to rogerl, but using hexadecimal (base 16), rather than base 4. The divisibility test for 5 in base 16 works like the divisibility test for 3 in base 10, because 3 divides (10-1) and 5 divides (16-1).
The base 16 representation of a positive integer $n$ is of the form
$$n = a_0 + a_1\cdot16 + a_2\cdot16^2 + a_3\cdot16^3 + a_4\cdot16^4 + \dots$$
with $0 \le a_i<16$.
But $16\equiv 1 \pmod{15}$, so
$$n \equiv a_0 + a_1 + a_2 + a_3 + a_4 + \dots \pmod{15}$$
And because 3 and 5 both divide 15, we also have
$$n \equiv a_0 + a_1 + a_2 + a_3 + a_4 + \dots \pmod{3}$$
$$n \equiv a_0 + a_1 + a_2 + a_3 + a_4 + \dots \pmod{5}$$
Thus we can test divisibility by 5 of a hex number by simply adding its hex digits, mod 5. (And of course we can get the hex digits of a binary number by grouping the bits in blocks of 4).
For example, $123_{10}$ is  $$0111 1011_2$$ in binary and $$\mathrm{7b}_{16}$$ in hex. The values of those two blocks are $7$ and $11$. $7 + 11 = 18 \equiv 3\pmod{5}$, so $$0111 1011_2$$ leaves a remainder of 3 when divided by 5.
Here are some larger examples.

dec 1000
bin 0011 1110 1000 
val    3   14    8 
sums   3    2    0 mod 5
remainder = 0
    
19136214
0001 0010 0011 1111 1110 1101 0110
   1    2    3   15   14   13    6
   1    3    1    1    0    3    4
remainder 4


Here's a link to a small live Python script which does these calculations.
As I said earlier, you can also use this method for divisibility by 3, just add mod 3 instead of 5. Or add mod 15, and test divisibility by 15, 5, and 3 at the same time.
Note that you can do this test in any order, but if you start from the left, don't forget to pad the bit string with zeroes (if necessary) to make the total number of bits divisible by 4.
