【发布时间】:2017-02-01 00:24:43
【问题描述】:
我有一个 Python 和 PowerShell 脚本,打算做同样的事情。当我在两个脚本中执行“非”运算符,然后 -1 % 256 操作时,我得到不同的输出:
PowerShell
-bnot 0: -1
(-1 % 256): -1
Python
(~0): -1
(-1 % 256): 255
而且,在不同的系统上,我再次从 PowerShell 获得不同的输出:
PowerShell
-bnot 0: 18446744073709551615
18446744073709551615 % 256: 255
Python
-bnot 0: -1
(-1 % 256): 255
如何让我的 PowerShell -bnot 和 % 运算符每次都产生与 Python 脚本相同的输出? PowerShell 版本相同。
【问题讨论】:
-
明确强制数字类型?在第二个例子中,你得到一个无符号整数。
-
你知道 Python 用的是什么吗?以及我将如何在 PowerShell 中强制执行此操作?
-
我周围没有窗户,但我想像
-bnot [int]0这样的东西应该可以。 -
不,我认为这不起作用。
-
实际上是 PowerShell v2.0 或更高版本?什么操作系统,哪个 PowerShell 主机(控制台或 ISE 或其他?) 什么 Python 版本?没有配置文件的 PowerShell?这两个系统有什么不同?你实际上是在做如图所示的测试,还是在使用变量?如果是这样,PowerShell 中的
$x.GetType()和 Python 中的type(x),它们是什么?
标签: powershell bit-manipulation powershell-2.0 bit twos-complement