|
|
| Practical Debugging in C++ (ISBN: 0130653942) |
 |
List Price: $20.80
Our Price: $20.80
Used Price: $19.09
Release Date: 15 January, 2002
Manufacturer: Prentice Hall (Paperback)
Sales Rank: 404,946
Author: Ann R. Ford, Toby J. Teorey
|
More Info
|
|
|
Bitwise Operators
|
2002-02-09 23:36:11
|
| |
cpp
|
|
|
|
|
Category: source:cpp:math
|
|
Description: Example of the different bitwise operators (or, and, xor, shift left, shift right)
|
|
Platform: unix/win
|
|
Author: detour
|
|
Viewed: 2423
|
|
Rating: 3.7/5 (17 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
/* bitwise.cpp written by detour@metalshell.com
*
* Bitwise Operators
* x & y = And X and Y ( 0001 & 0011 = 0001 )
* x | y = Or X and Y ( 0101 | 1100 = 1101 )
* x ^ y = Xor X and Y ( 0110 ^ 1100 = 1000 )
* ~x = Not X ( 1111 = 0000 )
* x << n = Shift x to the left n times ( multply by n^2 if n>1 )
* x >> n = Shift x to the right n times ( divide by n^2 if n>1 )
*
* http://www.metalshell.com/
*
*/
#include <stdio.h>
int main() {
int x = 11; // 1011
int y = 2; // 0010
printf("x = 1011\ny = 0010\n\n");
printf("x | y = %d\n", x|y);
printf("x & y = %d\n", x&y);
printf("x ^ y = %d\n", x^y);
printf("x << 3 = %d\n", x << 3);
printf("y >> 1 = %d\n", y >> 1);
}
|
|
|