我在PowerShell中有一串字符,如下所示:
Encoded: A35C454A
我想将每个字符视为十六进制值。在Ruby中,这就像Encoded[0].hex
一样简单。如何在PowerShell中执行此操作?
答案 0 :(得分:2)
Simples:
[Convert]::ToInt32($encoded[0], 16);
( ToInt16 也可以使用,但内置的 Int 类型实际上是 Int32 的简写)
答案 1 :(得分:-1)
请看看
function asciiToHex($a)
{
$b = $a.ToCharArray();
Foreach ($element in $b) {$c = $c + "%#x" + [System.String]::Format("{0:X}",
[System.Convert]::ToUInt32($element)) + ";"}
$c
}
http://learningpcs.blogspot.in/2009/07/powershell-string-to-hex-or-whatever.html