C语言的位操作及通过地址访问寄存器
1、unsigned int a, 将a的第11位置1,其他位保持不变。
a | = (0x1 <<11);
2、unsigned int a, 将a的第12位清0,其他位保持不变。
a & = ~(0x1 << 12);
3、unsigned int a, 将a的第13位取反,其他位保持不变。
a ^ = (0x1 << 13);
4、unsigned int a, 判断a的第14位是否为1?
int check(unsigned int a)
{
if(a & (0x1<<14))
return 1;
else
return 0;
}
5、已知地址0x40000000,将unsigned int的数据0x12345678写入该地址。
int *p = NULL;
p = (unsigned int *)0x40000000;
*P = 0x12345678;
6、已知地址0x40000000,读出该地址下的unsigned int型的数据。
unsigned int data;
data = ((unsigned int )0x40000000);