Skip to content

Instantly share code, notes, and snippets.

@wcarss
Created December 25, 2013 07:23
Embed
What would you like to do?
A test of bitwise and used to increment and wrap access into an array in doom's event-handling.
#include<stdio.h>
int main() {
int SIZE = 10;
int head = 0;
int tail = 0;
head = 3;
tail = 5;
printf("size-1: %d, head: %d, tail: %d, tail&SIZE-1: %d\n", SIZE-1, head, tail, tail&(SIZE-1));
for(; tail != head; tail = (++tail)&(SIZE-1)) {
printf("size-1: %d, head: %d, tail: %d, tail&SIZE-1: %d\n", SIZE-1, head, tail, tail&(SIZE-1));
}
printf("size-1: %d, head: %d, tail: %d, tail&SIZE-1: %d\n", SIZE-1, head, tail, tail&(SIZE-1));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment