📜  珀尔 | Math::BigInt->from_bin() 方法

📅  最后修改于: 2022-05-13 01:54:27.154000             🧑  作者: Mango

珀尔 | Math::BigInt->from_bin() 方法

Perl 中的Math::BigInt模块提供了表示具有任意精度和重载算术运算运算符的整数的对象。
Math::BigInt模块的from_bin()方法用于将作为输入传递的二进制数转换为其对应的十进制数。

示例 1:

perl
#!/usr/bin/perl
 
# Import Math::BigInt module
use Math::BigInt;
 
# Converting from binary to decimal
$x = Math::BigInt->from_bin("110100");
print("$x\n");
 
# Converting from binary to decimal
$x = Math::BigInt->from_bin("0b11001000");
print("$x\n");


perl
#!/usr/bin/perl
 
# Import Math::BigInt module
use Math::BigInt;
 
# Converting from binary to decimal
$x = Math::BigInt->from_bin("-110100");
print("$x\n");
 
# Converting from binary to decimal
$x = Math::BigInt->from_bin("-0b11001000");
print("$x\n");


输出:
52
200

示例 2:

perl

#!/usr/bin/perl
 
# Import Math::BigInt module
use Math::BigInt;
 
# Converting from binary to decimal
$x = Math::BigInt->from_bin("-110100");
print("$x\n");
 
# Converting from binary to decimal
$x = Math::BigInt->from_bin("-0b11001000");
print("$x\n");
输出:
-52
-200