The previous recipe was a simple conversion using a cast operator and string addition. Next, we will look at converting an integer into multiple bases, such as octal, hexadecimal, and binary strings.
Performing base conversions
How to do it...
The input will be taken as a string. The output would also be string, but with octal, hexadecimal, and binary representations. We will use a .NET accelerator for this:
- Open a new PowerShell file and type the following:
$InputString = Read-Host "Enter an integer" Write-Host "Octal representation: " -NoNewline Write-Host "$([Convert]::ToString($InputString, 8))" Write-Host "Hexadecimal representation: " -NoNewline Write-Host "$([Convert...