#include <stdio.h> int main (void) { unsigned int MAX = 32; unsigned int index = 31; index = 31; index = (index + 1) % MAX; // 这个容易理解 printf ("index = %d\n", index); index = 31; index = (index + 1) & (MAX - 1); // 这个运算效率高 printf ("index = %d\n", index); return; }
$ ./a.exe
index = 0
index = 0