The input will be taken as a string. The output would also be string, but the 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]::ToString($InputString, 16))" Write-Host "Binary representation: " -NoNewline Write-Host "$([Convert]::ToString($InputString, 2))"
- Run the script and enter an integer to get the octal, hexadecimal and binary representations of it.
Do not forget to try negative numbers as well.