当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


perl Math::BigInt->from_hex()用法及代码示例


Math::BigIntPerl中的module提供了代表具有任意精度的整数和重载算术运算符的对象。

Math::BigInt模块的from_hex()方法用于将作为输入传递的十六进制数转换为其相应的十进制数。

用法: Math::BigInt->from_hex()

参数:输入要转换的十六进制数

返回:传递的十六进制数的相应十进制数

范例1:

#!/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:

#!/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


相关用法


注:本文由纯净天空筛选整理自Code_Mech大神的英文原创作品 Perl | Math::BigInt->from_hex() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。