Dart int operator-bitwise-not
Syntax & Examples


int.operator-bitwise-not operator

The `~` operator in Dart performs a bit-wise negate operation on this integer.


Syntax of int.operator-bitwise-not

The syntax of int.operator-bitwise-not operator is:

operator ~() → int

This operator-bitwise-not operator of int the bit-wise negate operator.



✐ Examples

1 Bit-wise negate operation

In this example,

  1. We create an integer variable num1 with the value 5.
  2. We use the ~ operator to perform the bit-wise negate operation on num1.
  3. We then print the result to standard output.

Dart Program

void main() {
  int num1 = 5;
  int result1 = ~num1;
  print('Bit-wise negate of $num1: $result1');
}

Output

Bit-wise negate of 5: -6

2 Bit-wise negate operation

In this example,

  1. We create an integer variable num2 with the value 10.
  2. We use the ~ operator to perform the bit-wise negate operation on num2.
  3. We then print the result to standard output.

Dart Program

void main() {
  int num2 = 10;
  int result2 = ~num2;
  print('Bit-wise negate of $num2: $result2');
}

Output

Bit-wise negate of 10: -11

3 Bit-wise negate operation

In this example,

  1. We create an integer variable num3 with the value -3.
  2. We use the ~ operator to perform the bit-wise negate operation on num3.
  3. We then print the result to standard output.

Dart Program

void main() {
  int num3 = -3;
  int result3 = ~num3;
  print('Bit-wise negate of $num3: $result3');
}

Output

Bit-wise negate of -3: 2

Summary

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