取出a的第8-15位:
unsigned int a, b, mask = 0x0000ff00;
a = 0x12345678;
b = (a & mask) >> 8;
将a的8-15位清零:
unsigned int a, b, mask = 0x0000ff00;
a = 0x12345678;
b = a & ~mask;
将a的8-15位置1:
unsigned int a, b, mask = 0x0000ff00;
a = 0x12345678;
b = a | mask;
对寄存器赋值 0
xorl %eax, %eax // 对 eax 寄存器赋值 0 (效率要高于 movl %eax, $0)
实现位反转
b = a ^ (1<<i) // 对 a 的第 i 位进行反转 (0->1, 1->0)
进行奇偶校验
bit1 ^ bit2 ^ bit3 ^... ^ bitn // 结果为 1 ,则 1 的个数为奇数个,否则为偶数个
用于交换变量值
a = a ^ b;
b = b ^ a;
a = a ^ b;