- Perl ›
- builtin functions ›
- here
oct function - Converts an octal string to a decimal number
You can use the oct function to convert an octal string to a decimal number.
Conversion from octal to decimal
Use the oct function to convert from octal to decimal.
my $digit = oct('755');
Octal 755 becomes decimal 493.
In the above example, '755' is passed, but even if there is a leading 0 like '0755', it will be converted correctly.
Binary to Decimal Conversion
You can also use the oct function to convert a binary string to a decimal number. The oct function is originally a function that converts an octal number to a decimal number, but if a string prefixed with 0b is passed as an argument, the binary number string is converted to a decimal number.
my $digit = oct('0b101');
A little more about base conversion
You can use hex function to convert from hexadecimal to decimal.
If you want to know a little more about binary conversion such as binary, octal, hexadecimal, etc., please refer to the following articles.