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
#!/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";
}
Output:
Example 2: Use of 89132506319263974586 is an even number 98793270075788553683446589224555431 is not an even number
Math::BigInt->is_even() method to check whether a hexadecimal number is an even number in decimal or not.
#!/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";
}
Output:
Example 3: Use of 0x24CB016EA is an even number in decimal
Math::BigInt->is_even() method to check whether a binary number is an even number in decimal or not.
#!/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";
}
Output:
0b1001001100101100000001011011101010 is an even Number in decimal