Converting radix in PowerShell
Convert a string to a specified radix string
# Hexadecimal -> Binary
PS> [convert]::ToString(0xFF,2)
11111111
PS> [convert]::ToString("0xFF",2)
11111111
# Hexadecimal -> Decimal
PS> [convert]::ToString(0xFF,10)
255
PS> [convert]::ToString("0xFF",10)
255
# Decimal -> Hexadecimal
PS> [convert]::ToString(255,16)
ff
PS> [convert]::ToString("255",16)
ff
# Decimal -> Hexadecimal (Example using the -f operator)
PS> '{0:x}' -f 255
ff
PS> '{0:X}' -f 255
FF
# Decimal -> Binary
PS> [convert]::ToString(255,2)
11111111
PS> [convert]::ToString("255",2)
11111111
Conversion from unprefixed string to int
If no prefix (such as “0x” or “0b”).
# Hexadecimal -> Decimal
PS> [Convert]::ToInt32("FF",16)
255
# Binary -> Decimal
PS> [Convert]::ToInt32("11111111",2)
255
View file binary in Format-Hex
You will often see hexadecimal numbers in file binaries.
Use the Format-Hex cmdlet to see the binary of a file in PowerShell.
PS C:\> Format-Hex .\Hello.txt
Path: C:\Hello.txt
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 48 65 6C 6C 6F Hello
PS C:\> Get-Content .\Hello.txt
Hello