A conceptually simpler way to do this is to assign one (or more) extra bits in the head an tail pointers. For example, for a 512 entry ring, use 16-bit indices. Whenever you index the ring, and the index with 511 before performing the index.<p><pre><code> Write to ring: ring[511&(head++)] = data
Read from ring: data = ring[511&(tail++)]
Ring is empty: head == tail
Ring is full: tail + 512 == head</code></pre>