gpt4 book ai didi

powershell - 在 PowerShell 中将十六进制转换为 ASCII

转载 作者:行者123 更新时间:2023-12-01 18:00:50 24 4
gpt4 key购买 nike

我有一系列十六进制值,如下所示:

68 65 6c 6c 6f 57 6f 72 6c 64 7c 31 2f 30 38 31 35 7c 41 42 43 2d 31 35 02 08

我现在需要将此十六进制值转换为 ASCII,以便结果如下所示:

helloWorld|1/0815|ABC-15

我尝试了很多东西,但从未得到最终的代码。我尝试以各种可以想象的方式使用转换函数,但没有成功。

目前我使用 this website进行转换,但我需要在我的 PowerShell 脚本中执行此操作。

最佳答案

很像Phil P.'s approach ,但使用 -split-join 运算符(另外,不需要整数,ASCII 字符将适合 [byte]):

$hexString = "68 65 6c 6c 6f 57 6f 72 6c 64 7c 31 2f 30 38 31 35 7c 41 42 43 2d 31 35 02 08"
$asciiChars = $hexString -split ' ' |ForEach-Object {[char][byte]"0x$_"}
$asciiString = $asciiChars -join ''
$asciiString

关于powershell - 在 PowerShell 中将十六进制转换为 ASCII,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41762760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com