HexToASCII

Converts a string of hexidecimals to an ASCII encoded string
Language:
PowerShell
Keywords:
PowerShell;Encoding
Code Snippet

function HexToASCII($hex) {
    $bytes = $hex.Substring(2-split '([a-f0-9]{2})' | foreach-object { if ($_) {[System.Convert]::ToByte($_,16)}}
    $outval = [System.Text.Encoding]::ASCII.GetString($bytes)
    return $outval;
}

Example

HexToASCII "0x3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D227574662D38223F3E0D"

OUTPUT: <?xml version="1.0" encoding="utf-8"?>

Created 2014-04-29
comments powered by Disqus
Login