Bitwise Operators
This class of operators contain those operators which are used to perform bitwise operation on the operands. It goes like this:
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 one operand. |
<< | 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. |
>>> | Unsigned Shift right | Shifts a in binary representation to b bits to left (it ignores sign). |
Example: Using Bitwise Operators in the program
// Dart Program to Demonstrate
// Use of Dart Bitwise Operators
void main()
{
print("Demonstrate use of Dart Bitwise Operators");
int a = 5;
int b = 7;
// Performing Bitwise AND on a and b
var c = a & b;
print("a & b : $c");
// Performing Bitwise OR on a and b
var d = a | b;
print("a | b : $d");
// Performing Bitwise XOR on a and b
var e = a ^ b;
print("a ^ b : $e");
// Performing Bitwise NOT on a
var f = ~a;
print("~a : $f");
// Performing left shift on a
var g = a << b;
print("a << b : $g");
// Performing right shift on a
var h = a >> b;
print("a >> b : $h");
var i = -a >>> b;
print("-a >>> b : $i");
}
Output:
Demonstrate use of Dart Bitwise Operators
a & b : 5
a | b : 7
a ^ b : 2
~a : 4294967290
a << b : 640
a >> b : 0
-a >>> b : 33554431
Operators in Dart
The operators are special symbols that are used to carry out certain operations on the operands. The Dart has numerous built-in operators which can be used to carry out different functions, for example, ‘+’ is used to add two operands. Operators are meant to carry operations on one or two operands.
Contact Us