Convert Binary to Decimal and vice-versa
To convert a binary number to decimal base, use unpack and pack.
my $binnum = '1101'; # binary number my $decnum = unpack("N", pack("B32", substr('0'x32.$binnum, -32))); print "$binnum = $decnum n";
To convert a decimal number to binary, use unpack.
my $decnum = 25; # decimal number my $binnum = unpack("B32", pack("N", $decnum)); # in binary $binnum =~ s!^0+(?=d)!!; print "$decnum = $binnum n";
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.