Skip to content

Instantly share code, notes, and snippets.

@wcarss
Created December 25, 2013 07:23
Show Gist options
  • Save wcarss/8120951 to your computer and use it in GitHub Desktop.
Save wcarss/8120951 to your computer and use it in GitHub Desktop.
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