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;
}
// 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;
}
相关文章推荐
- General Object Initiating Function by the Example of $injector.instantiate Implementation in angular
- 【MongoDB】The basic operation of Index in MongoDB
- ERROR:the server has either erred or is incapable of performing the requested operation
- The server has either erred or is incapable of performing the requested operation. (HTTP 500)
- Which of the following statement(s) equal(s) value 1 in C programming language?
- The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider i
- About the Rebase and Bind operation in the production of software
- The Excel Connection Manager is not supported in the 64-bit version of SSIS
- 【MongoDB】The basic operation of Index in MongoDB
- The Evolution of Distributed Programming in R
- An Example about the use of map Container in C++ STL / c++ map容器的用法
- The server has either erred or is incapable of performing the requested operation. (HTTP 500)
- The art in general operation of linux
- Error occurred in deployment step ‘Activate Features’: Operation is not valid due to the current state of the object
- The art in general operation of Windows
- Programming in the Key of C#
- SSIS错误之"The Excel Connection Manager is not supported in the 64-bit version of SSIS"
- the basic operation of sequence in python
- The amazing efficiency of pointer in C Programming Language