珀尔 | Math::BigInt->from_hex() 方法
Perl 中的Math::BigInt模块提供了表示具有任意精度和重载算术运算运算符的整数的对象。
Math::BigInt模块的from_hex()方法用于将作为输入传递的十六进制数转换为其对应的十进制数。
Syntax: Math::BigInt->from_hex()
Parameter: input hexadecimal number to be converted
Returns: a corresponding decimal number of the passed hexadecimal number
示例 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");
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");
输出:
1000
55130
示例 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");
输出:
-1000
-55130