How to Convert Octal String to Decimal Number in PowerShell
Introduction
Converting one type to another type is a common problem in scripting including converting octal number in form of string to decimal number.
In this blog post, we will walk through how to convert Octal String to Decimal number.
Solution
Using Convert class from .NET Framework
.NET Framework classes provide some methods for performing various types of data conversion tasks including converting string into octal number which is of integer type.
The most commonly used class is System.Convert
which provides several static methods that are specifically designed for converting string into different data types such as int, double, etc.
To get list of static methods that can be used for conversion, we can use following command:
[Convert] | Get-Member -Static
Later, to convert octal number in form of string to decimal, we can use following script:
$string = "764"
$num = [Convert]::ToInt32($string, 8)
Write-Host $num
The output of above script is 500.
Conclusion
In conclusion, to convert octal string to decimal number we can use method provided by System.Convert
class from .NET Framework.