In most cases, strings may be cast back to numeric values. Consider the following example:
[Int]"2" # String to Int32 [Decimal]"3.141" # String to Decimal [UInt32]10 # Int32 to UInt32 [SByte]-5 # Int32 to SByte
For advanced conversions, the System.Convert class may be used. The Convert class includes static methods that can take a string and convert it into a number using a specified base.
A binary (base 2) value is converted as follows:
[Convert]::ToInt32('01000111110101', 2) # Returns 4597
A hexadecimal (base 16) value can be converted like so:
[Convert]::ToInt32('FF9241', 16) # Returns 16749121
The bases that Convert supports are 2 (binary), 8 (octal), 10 (denary), and 16 (hexadecimal).