/**********************************************************************
* RightMove.cpp
* Compiler: GCC,VS,VC6.0 win32
* Author:WK
* Time: 2015 3 29
************************************************************************/
#include<stdio.h>
void bit_set(unsigned int *p_data,
unsigned int position, bool flag)
{
if(flag)
{
*p_data |= (0x01<<(position-1));
}
else
{
int c=(0x01<<(position-1));
*p_data &= ~c;
}
}
void main()
{
//unsigned int ch = 'A';
unsigned int ch=3;
bit_set(&ch,3,false);
// bit_set(&ch,1,true);
printf("%d\n",ch);
}

本文详细介绍了C++中位操作符的使用方法及应用案例,包括位设置、位清零、位翻转等常见操作,通过实例帮助读者理解并掌握C++位运算的基本技巧。
5万+

被折叠的 条评论
为什么被折叠?



