Dart int operator-right-shift
Syntax & Examples
int.operator-right-shift operator
The `>>` operator in Dart shifts the bits of this integer to the right by a specified amount.
Syntax of int.operator-right-shift
The syntax of int.operator-right-shift operator is:
operator >>(int shiftAmount) → intThis operator-right-shift operator of int shift the bits of this integer to the right by shiftAmount.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
shiftAmount | required | The number of positions to shift the bits to the right. |
✐ Examples
1 Bit-wise right shift
In this example,
- We create an integer variable
num1with the value 8 and a shift amount of 2. - We use the `>>` operator to perform the bit-wise right shift operation on
num1. - We then print the result to standard output.
Dart Program
void main() {
int num1 = 8;
int shiftAmount1 = 2;
int result1 = num1 >> shiftAmount1;
print('Right shift of $num1 by $shiftAmount1 positions: $result1');
}Output
Right shift of 8 by 2 positions: 2
2 Bit-wise right shift
In this example,
- We create an integer variable
num2with the value 16 and a shift amount of 3. - We use the `>>` operator to perform the bit-wise right shift operation on
num2. - We then print the result to standard output.
Dart Program
void main() {
int num2 = 16;
int shiftAmount2 = 3;
int result2 = num2 >> shiftAmount2;
print('Right shift of $num2 by $shiftAmount2 positions: $result2');
}Output
Right shift of 16 by 3 positions: 2
3 Bit-wise right shift
In this example,
- We create an integer variable
num3with the value 32 and a shift amount of 1. - We use the `>>` operator to perform the bit-wise right shift operation on
num3. - We then print the result to standard output.
Dart Program
void main() {
int num3 = 32;
int shiftAmount3 = 1;
int result3 = num3 >> shiftAmount3;
print('Right shift of $num3 by $shiftAmount3 positions: $result3');
}Output
Right shift of 32 by 1 positions: 16
Summary
In this Dart tutorial, we learned about operator-right-shift operator of int: the syntax and few working examples with output and detailed explanation for each example.