gpt4 book ai didi

powershell - 使用 PowerShell 将二进制整数写入文件

转载 作者:行者123 更新时间:2023-12-02 22:56:14 25 4
gpt4 key购买 nike

我正在尝试使用 PowerShell 将无符号整数(它的 4 字节 DWORD 二进制表示)写入文件,但我尝试过的所有替代方法都只写入文本。

假设我有这个号码:

$number = [Int] 255

文件内容应该是FF000000(二进制),而不是255(文本)。

我不是 PowerShell 专家,所以我很感激任何帮助。

最佳答案

找到解决方案:

$number = [Int] 255
# Convert the number to a byte[4] array
$bytes = [System.BitConverter]::GetBytes($number)
# Write the bytes to a file
Add-Content -Path "D:\FILE.BIN" -Value $bytes -Encoding Byte

关于powershell - 使用 PowerShell 将二进制整数写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41274180/

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