Fast answer : modulo. I'll elaborate later.
Edit: So, what you want to know is :
does A equal to 0, 20, 40, 60, etc. ? , i.e. is A a multiple of 20 ?
The modulo of A and 20 (denoted A % 20 in Python, and IIRC in C too) is the remainder in the (euclidean, or integer) division of A by 20.
For example, 68 / 20 = 3, and the remainder is 68 - 20*3 = 8, so 68 % 20 = 8.
To state that A is a multiple of 20 is the same as stating that A % 20 = 0.
So your test should be :
Code: Select all
if (A % 20 == 0) || ((A + 1) % 20 == 0)
Or even better (because you compute only one modulo) :
Code: Select all
B = A % 20;
if ((B == 0) || (B == 19))
That said, computing a modulo is like computing a division : it's slow. Except in case the right term is a power of 2. In this case, the modulo is given by the right-most bits. For example, computing modulo 2^5 = 32 is the same as keeping the 5 right-mosts bits, so A % 32 is the same as A & 0x1F.
So you should make your rows 32 bytes long (by padding) and your test should be :
Code: Select all
B = A & 0x1F;
if ('B == 0) || (B == 19))