- Bitwise operators are used to perform bit-level operations on operands which means they performed on single bits.
Operator Symbol | Operator Name | Operator Description | |
& | Bitwise AND | Performs bitwise and operation on two operands. | |
Bitwise OR | Performs bitwise or operation on two operands. | ||
^ | Bitwise XOR | Performs bitwise XOR operation on two operands. | |
~ | Bitwise NOT | Performs bitwise NOT operation on two operands. | |
<< | Left Shift | Shifts a in binary representation to b bits to left and inserting 0 from right. | |
\>> | Right Shift | Shifts a in binary representation to b bits to left and inserting 0 from left. |
void main()
{
int a = 5;
int b = 7;
// Performing Bitwise AND on a and b
var c = a & b;
print(c); //5
// Performing Bitwise OR on a and b
var d = a | b;
print(d); //7
// Performing Bitwise XOR on a and b
var e = a ^ b;
print(e); //2
// Performing Bitwise NOT on a
var f = ~a;
print(f); //-6
// Performing left shift on a
var g = a << b;
print(g); //640
// Performing right shift on a
var h = a >> b;
print(h); //0
}
ย