Archive

Powershell Value Conversions

 

dec to hex

1 2 3 4 5 6 PS> "{0:x}" -f 397312 61000 PS> [String]::Format("{0:x}", 397312) 61000 PS> [Convert]::ToString(397312, 16) 61000

If you want the hex number to have 6 digits then use

1 2 PS> "{0:x6}" -f 397312 061000

hex to dec

1 2 3 4 5 6 7 8 PS> "{0:d}" -f 0x61000 397312   PS> [String]::Format("{0:d}", 0x61000) 397312   PS> [Convert]::ToString(0x061000, 10) 397312

dec to bin

1 2 PS> [Convert]::ToString(129, 2) 10000001

hex to bin

1 2 PS> [Convert]::ToString(0x81, 2) 10000001

 

Also useful:

Convert from UNICODE string to base64 string:

[System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes("your unicode string")).ToString()

 

Convert Base64 string back to string:

[System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String("Base64 string here"))