位運算具體應用、算法
位左爲最高位、右爲最低爲、從右往左看、code
#define a(c) (1<<(c)) int main() { int b; for ( b = 0; b < 20; b++) { printf("a(%d)=%d\n", b, a(b)); } }
#define a(c) (1<<(c)) int main() { enum b { b1 = a(0), b2 = a(1), b3 = a(2), b4 = a(3), b5 = a(4), b6 = a(5), b7 = a(6), b8 = a(7), }; unsigned int e = 0; //顯示6 修改6 if (e & b6) { printf("顯示6\n"); } else { printf("沒顯示\n"); e = e | b6; } if (e & b6) { printf("顯示6\n"); } else { printf("沒顯示\n"); } }
經常使用於算法和密碼學、class