Dart BigInt isEven
Syntax & Examples

BigInt.isEven property

The `isEven` property checks whether a given big integer is even.


Syntax of BigInt.isEven

The syntax of BigInt.isEven property is:

 bool isEven 

This isEven property of BigInt whether this big integer is even.

Return Type

BigInt.isEven returns value of type bool.



✐ Examples

1 Check Evenness of Positive and Negative Numbers

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with 10 and 15 respectively.
  2. We then use the isEven property to check if these numbers are even.
  3. We print the results to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(10);
  BigInt num2 = BigInt.from(15);
  bool isEven1 = num1.isEven;
  bool isEven2 = num2.isEven;
  print('10 is even: $isEven1');
  print('15 is even: $isEven2');
}

Output

10 is even: true
15 is even: false

2 Check Evenness of a Negative Number

In this example,

  1. We create a BigInt object, num, initialized with -7.
  2. We then use the isEven property to check if this number is even.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(-7);
  bool isEven = num.isEven;
  print('-7 is even: $isEven');
}

Output

-7 is even: false

3 Check Evenness of a Large Number

In this example,

  1. We create a BigInt object, num, by parsing the string '123456789012345678901234567890'.
  2. We then use the isEven property to check if this large number is even.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.parse('123456789012345678901234567890');
  bool isEven = num.isEven;
  print('Large number is even: $isEven');
}

Output

Large number is even: false

Summary

In this Dart tutorial, we learned about isEven property of BigInt: the syntax and few working examples with output and detailed explanation for each example.