Perl | Math::BigInt->brsft() method
Last Updated :
13 Sep, 2021
Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.
brsft() method of Math::BigInt module is used to right shift the given value by a base given as parameter.
Syntax: Math::BigInt->brsft()
Parameter:
$y- number of times shifting is to be done
$n- base of shifting
Returns: a result by dividing the number by the base by given number of times
Note: By default it takes 2 as a base.
Example 1:
perl
#!/usr/bin/perl
use Math::BigInt;
$x = Math::BigInt->new(25);
$x ->brsft(1);
print ( "$x\n" );
$x = Math::BigInt->new(2345);
$x ->brsft(2, 10);
print ( $x );
|
There is an exception with the negative value and that is only with the base 2, the output will be the difference between the actual output and the original number. Following example will make it clear:
Example 2:
perl
#!/usr/bin/perl
use Math::BigInt;
$x = Math::BigInt->new(31);
$x ->brsft(1);
print ( "$x\n" );
$x = Math::BigInt->new(-31);
$x ->brsft(1);
print ( $x );
|
Share your thoughts in the comments
Please Login to comment...