Perl | Math::BigInt->is_even() method

Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.

is_even() method of Math::BigInt module is used to check whether a number stored as BigInt object is even or not.

Syntax: Math::BigInt->is_even()

Parameter: None

Returns: true if the number stored in BigInt object is an even number, otherwise returns false.



Example 1: Use of Math::BigInt->is_even() method

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl 
  
# Import Math::BigInt module
use Math::BigInt;
  
# Value of n
$n = '89132506319263974586';
  
# Create BigInt object
$x = Math::BigInt->new($n);
  
# Check if the number stored
# in BigInt object is even or not
$isEven = $x->is_even();
  
if ($isEven)
{
    print "$n is an even number\n";
}
  
else
{
    print "$n is not an even number\n";
}
  
# Value of n
$n = '98793270075788553683446589224555431';
  
# Create BigInt object
$x = Math::BigInt->new($n);
  
# Check if the number stored
# in BigInt object is even or not
$isEven = $x->is_even();
  
if ($isEven)
{
    print "$x is an even number";
}
  
else
{
    print "$x is not an even number";
}

chevron_right


Output:

89132506319263974586 is an even number
98793270075788553683446589224555431 is not an even number

Example 2: Use of Math::BigInt->is_even() method to check whether a hexadecimal number is an even number in decimal or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl 
  
# Import Math::BigInt module
use Math::BigInt;
  
# Hexadecimal string
$hexValue = '0x24CB016EA';
  
  
# value of '0x24CB016EA' in
# decimal number system is 9876543210
  
  
# Create BigInt object
$x = Math::BigInt->new($hexValue);
  
# Check whether the Hexadecimal 
# number stored as BigInt object
# is an even number or not 
# using Math::BigInt->is_even() method
$isEven = $x->is_even();
  
if($isEven)
{
    print "$hexValue is an even number in decimal";
}
  
else
{
    print "$hexValue is not an even number in decimal";
}

chevron_right


Output:

0x24CB016EA is an even number in decimal

Example 3: Use of Math::BigInt->is_even() method to check whether a binary number is an even number in decimal or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl 
  
# Import Math::BigInt module
use Math::BigInt;
  
# Binary string
$binary = '0b1001001100101100000001011011101010';
  
  
# 0b1001001100101100000001011011101010
# is 9876543210 in decimal 
  
# Create BigInt object
$x = Math::BigInt->new($binary);
  
# Check whether the Binary
# number stored as BigInt object
# is an even number or not 
# using Math::BigInt->is_even() method
$isEven = $x->is_even();
  
if($isEven)
{
    print "$binary is an even Number in decimal";
}
  
else
{
    print "$binary is not an even number in decimal";
}

chevron_right


Output:

0b1001001100101100000001011011101010 is an even Number in decimal



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.