您的位置:首页 > 运维架构

The example of Bit Operation in C programming

2007-03-31 08:48 405 查看
// The rule of bit operations is from the formula of the operations
// i.e The result of the bit operation depends on the binary form of the number and the operator

//From the rule, we know:

// The result of an AND(&) comparison is 1 when both bits being compared are 1s; otherwise the result is 0.

// The SHIFT(<< and >>) operator causes the bitss in an operand to be shifted to the left(right) by a given amount.

// So we can calculate by this rule and yield the following test code.

//For Turbo c++:

#include<stdio.h>
int main()
{
printf("5&4=%d",(5&4));
printf("4>>1=%d",(4>>1));
printf("5<<2=",(5<<2));
return 0;
}

//For Dev-C++ and VC++:

#include<iostream>
using namespace std;
#include<stdio.h>
#include<conio.h>
int main()
{
cout<<"5&4="<<(5&4)<<endl;
cout<<"4>>1="<<(4>>1)<<endl;
cout<<"5<<2="<<(5<<2)<<endl;
getche();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: