Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.
from_hex() method of Math::BigInt module is used to convert the hexadecimal number passed as input to its corresponding decimal number.
Syntax: Math::BigInt->from_hex()
Parameter: input hexadecimal number to be converted
Returns: a corresponding decimal number of the passed hexadecimal number
Example 1:
perl
#!/usr/bin/perl # Import Math::BigInt module use Math::BigInt;
# Converting from hexadecimal to decimal $x = Math::BigInt->from_hex( "3E8" );
print ( "$x\n" );
# Converting from hexadecimal to decimal $x = Math::BigInt->from_hex( "D75A" );
print ( "$x\n" );
|
Output:
1000 55130
Example 2:
perl
#!/usr/bin/perl # Import Math::BigInt module use Math::BigInt;
# Converting from hexadecimal to decimal $x = Math::BigInt->from_hex( "-3E8" );
print ( "$x\n" );
# Converting from hexadecimal to decimal $x = Math::BigInt->from_hex( "-D75A" );
print ( "$x\n" );
|
Output:
-1000 -55130