注册 集 与 删除 -- C

文章3位设置和清除操作。


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BIT3 (0x1<<3)

int
main()
{
	int a = 0x00000000;

	printf("a = 0x%08X
", a);
	/*
		置位第3bit
		a = a | (0x1<<3)
		a = a | 0x8
	*/
	a |= BIT3;
	printf("a = 0x%08X
", a);
	
	/*
		清楚第3bit
		a = a & ~ (0x1<<3)
		a = a & ~ 0x8
		a = a & 0xfffffff7
	*/
	a &= ~BIT3;//
	printf("a = 0x%08X
", a);
}
/*
[root@localhost test_class]# gcc quote.cpp ;./a.out
a = 0x00000000
a = 0x00000008
a = 0x00000000
*/


版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/mengfanrong/p/4882535.html