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 ~() → intThis operator-bitwise-not operator of int the bit-wise negate operator.
✐ Examples
1 Bit-wise negate operation
In this example,
- We create an integer variable
num1with the value 5. - We use the
~operator to perform the bit-wise negate operation onnum1. - 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,
- We create an integer variable
num2with the value 10. - We use the
~operator to perform the bit-wise negate operation onnum2. - 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,
- We create an integer variable
num3with the value -3. - We use the
~operator to perform the bit-wise negate operation onnum3. - 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.