casio1374633

导航

 
#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

posted on 2013-04-29 21:02  casio1374633  阅读(168)  评论(0编辑  收藏  举报