Powershell: Convert Hex to Int type

Hi,

short post today. Topic: convert a hex string to an integer type.

This can be done by a simple cast. Consider to use try/catch to handle any exceptions.

$sMyHexValue="0xff"
$iInt=[Int32]$sMyHexValue
write-host "HexString:" $sMyHexValue  "HexFormatedFromInt" ([string]::Format("0x{0:x}",$iInt)) "Int:" $iInt
HexString: 0xff HexFormatedFromInt 0xff Int: 255

Michael

One thought on “Powershell: Convert Hex to Int type”

Leave a Reply Cancel reply