【发布时间】:2020-10-19 16:31:09
【问题描述】:
总结
我正在尝试使用 PowerShell 版本 7 将 32 位 BitArray 转换为整数。我尝试了 C# 处理它的方式,但它不起作用。
这是我的代码。
$high = [System.Collections.BitArray]::new(@(0x93e0))
$low = [System.Collections.BitArray]::new(@(0x0004))
$low += $high.LeftShift(16)
# Create an integer array with a length of 1
$result = [int[]]::new(1)
# Copy the BitArray to the integer at index 0
$low.CopyTo($result), 0)
实际结果
抛出异常。
MethodInvocationException: Exception calling "CopyTo" with "2" argument(s): "Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray')"
预期结果
$result 变量填充了以整数表示的BitArray 的值。
【问题讨论】:
-
$low += $high.LeftShift(16)正在将$low变成 64 长度。因此,关于长度不足的错误。
标签: powershell bit-manipulation bitarray bitvector