Modulo and Divide Operation

Let's say you've an array like

[ a1, a2,...aN, b1, b2,...bN, c1, c2 .....cN ]

These are blocks of N size.

Division is usual to skip over blocks. So let's say you want to access an element in 2nd block whose index is N + 3. Then:

(N + 3)/N = 1 (Means skip first block)

Modulo can be used to find the index within that block:

(N + 3)%N = 3 (Element at 3 index in that block)

Comments