bitwise-operators
bitwise-operators
Bitwise Operators in C
Programming
In the arithmetic-logic unit (which is within the CPU),
mathematical operations like: addition, subtraction,
multiplication and division are done in bit-level. To
perform bit-level operations in C programming, bitwise
operators are used.
| Bitwise OR
^ Bitwise XOR
~ Bitwise complement
Shift left
#include <stdio.h>
int main() {
return 0;
}
Run Code
Output
Output = 8
Bitwise OR Operator |
The output of bitwise OR is 1 if at least one corresponding
bit of two operands is 1. In C Programming, bitwise OR
operator is denoted by | .
Example 2: Bitwise OR
#include <stdio.h>
int main() {
return 0;
}
Run Code
Output
Output = 29
#include <stdio.h>
int main() {
return 0;
}
Run Code
Output
Output = 21
2's Complement
Two's complement is an operation on binary numbers. The
2's complement of a number is equal to the complement
of that number plus 1. For example:
instead of 220.
#include <stdio.h>
int main() {
return 0;
}
Run Code
Output
Output = -36
Output = 11
Shift Operators in C programming
There are two shift operators in C programming:
#include <stdio.h>
int main() {
int num=212, i;
return 0;
}
Run Code