Open In App

Perl | Math::BigInt->from_bin() method

Improve
Improve
Like Article
Like
Save
Share
Report

Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators.
from_bin() method of Math::BigInt module is used to convert the binary number passed as input to its corresponding decimal number.
 

Syntax: Math::BigInt->from_bin()
Parameter: input binary number to be converted
Returns: a corresponding decimal number of the passed binary number

Example 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");


Output: 

52
200

 

Example 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");


Output: 

-52
-200

 


Last Updated : 09 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads