There is simple technique to extract remainder when a number is divided by another number (divisor) that is power of 2?
Read full article from Optimization Techniques | Set 1 (Modulus) | GeeksforGeeks
N%2 = N & (2-1) = 1010111 & 1 = 1 = 1
N%4 = N & (4-1) = 1010111 & 11 = 11 = 3
N%8 = N & (8-1) = 1010111 & 111 = 111 = 7
N%16 = N & (16-1) = 1010111 & 1111 = 111 = 7
N%8 = N & (8-1) = 1010111 & 111 = 111 = 7
N%16 = N & (16-1) = 1010111 & 1111 = 111 = 7
N%32 = N & (32-1) = 1010111 & 11111 = 10111 = 23
Modulus operation over exact powers of 2 is simple and faster bitwise ANDing. This is the reason, programmers usually make buffer length as powers of 2.
Implementation of circular queue (ring buffer) using an array. Omitting one position in the circular buffer implementation can make it easy to distinguish between full and empty conditions. When the buffer reaches SIZE-1, it needs to wrap back to initial position. The wrap back operation can be simple AND operation if the buffer size is power of 2. If we use any other size, we would need to use modulus operation.