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

Advertisment to support michlstechblog.info

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.