Perl | Math::BigInt->is_odd() method
Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.
is_odd() method of Math::BigInt module is used to check whether a number stored as BigInt object is an odd number or not.
Syntax: Math::BigInt->is_odd()
Parameter: None
Returns: true if the number stored in BigInt object is an odd number, otherwise returns false.
Example 1: Use of Math::BigInt->is_odd() method
#!/usr/bin/perl # Import Math::BigInt module use Math::BigInt; # Value of n $n = '89123751682746'; # Create BigInt object $x = Math::BigInt->new($n); # Check if the number stored # in BigInt object is # an odd number or not $isOdd = $x->is_odd(); if ($isOdd) { print "$n is an odd number\n"; } else{ print "$n is not an odd number\n"; } # Value of n $n = '6348762649837957979685908708650797587783'; # Create BigInt object $x = Math::BigInt->new($n); # Check if the number stored # in BigInt object is # an odd number or not $isOdd = $x->is_odd(); if ($isOdd) { print "$n is an odd number\n"; } else{ print "$n is not an odd number\n"; } |
89123751682746 is not an odd number 6348762649837957979685908708650797587783 is an odd number
Example 2: Use of Math::BigInt->is_odd() method to check whether Octal number is an odd number in decimal or not.
#!/usr/bin/perl # Import Math::BigInt module use Math::BigInt; # Octal number represented as string $octal = 726746425; # value of octal '726746425' is # 123456789 in decimal number system # Create BigInt object $x = Math::BigInt->from_oct($octal); # Check whether the Octal # number stored in BigInt object # is an odd number or not # using Math::BigInt->is_odd() method $isOdd = $x->is_odd(); if($isOdd) { print "$octal (in octal) is an odd number in decimal"; } else{ print "$octal (in octal) is not an odd number in decimal"; } |
726746425 (in octal) is an odd number in decimal
Example 3: Use of Math::BigInt->is_odd() method to check whether a hexadecimal is an odd number in decimal or not.
#!/usr/bin/perl # Import Math::BigInt module use Math::BigInt; # Hexadecimal number represented as string $hex = 'Ox112210F4B16C1CB1'; # Hexadecimal value '0x112210F4B16C1CB1' is # 1234567890987654321 in decimal number system # Create BigInt object $x = Math::BigInt->new($hex); # Check whether the hexadecimal # number stored in BigInt object # is an odd number or not # using Math::BigInt->is_odd() method $isOdd = $x->is_odd(); if($isOdd) { print "$hex (in hexadecimal) is an odd number in decimal"; } else{ print "$hex (in hexadecimal) is not an odd number in decimal"; } |
Ox112210F4B16C1CB1 (in hexadecimal) is an odd number in decimal
Recommended Posts:
- Perl | Method Overriding in OOPs
- Perl | Basic Syntax of a Perl Program
- Perl | Math::BigInt->from_bin() method
- Perl | Math::BigInt->is_even() method
- Perl | Math::BigInt->bone() method
- Perl | Math::BigInt->from_oct() method
- Perl | Math::BigInt->length() method
- Perl | Math::BigInt->bnan() method
- Perl | Math::BigInt->bfac() method
- Perl | Math::BigInt->from_hex() method
- Perl | Math::BigInt->bneg() method
- Perl | Math::BigInt->brsft() method
- Perl | Math::BigInt->binf() method
- Perl | Math::BigInt->config() method
- Perl | Math::BigInt->digit() method
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.



