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