Dart int operator-left-shift
Syntax & Examples


int.operator-left-shift operator

The `<<` operator in Dart shifts the bits of this integer to the left by the specified amount.


Syntax of int.operator-left-shift

The syntax of int.operator-left-shift operator is:

operator <<(int shiftAmount) → int

This operator-left-shift operator of int shift the bits of this integer to the left by shiftAmount.

Parameters

ParameterOptional/RequiredDescription
shiftAmountrequiredThe number of positions to shift the bits to the left.


✐ Examples

1 Left shifting by 2 positions

In this example,

  1. We assign the value 5 to the integer variable num.
  2. We left shift num by 2 positions using the << operator.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 5;
  int shiftedNum = num << 2;
  print('Result of left shifting $num by 2 positions: $shiftedNum');
}

Output

Result of left shifting 5 by 2 positions: 20

2 Left shifting by 3 positions

In this example,

  1. We assign the value 10 to the integer variable num.
  2. We left shift num by 3 positions using the << operator.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 10;
  int shiftedNum = num << 3;
  print('Result of left shifting $num by 3 positions: $shiftedNum');
}

Output

Result of left shifting 10 by 3 positions: 80

3 Left shifting by 1 position

In this example,

  1. We assign the value 3 to the integer variable num.
  2. We left shift num by 1 position using the << operator.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 3;
  int shiftedNum = num << 1;
  print('Result of left shifting $num by 1 position: $shiftedNum');
}

Output

Result of left shifting 3 by 1 position: 6

Summary

In this Dart tutorial, we learned about operator-left-shift operator of int: the syntax and few working examples with output and detailed explanation for each example.