Number Conversion Functions in Perl

1. What are Number Conversion Functions in Perl?
2. How to convert hexadecimal to decimal and string to integer?

Explanation

hex() Function:


The hex() function is used to get the decimal values for the given hexadecimal number.

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
print hex '0xFf';
print "<br>";
print hex 'fF';
Result :

255
255

oct() Function:


The oct() function converts a string to an octal number.

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
print "Octal value of 65 is::", oct('65'),"n";
print "<br>";
print "Octal value of 46 is::", oct('46'),"n";
Result :

Octal value of 65 is::53
Octal value of 46 is::38

Ask Questions

Ask Question