I have a decimal value 163 that I need to do a unary "not" operation on. In C++ and Java, this would look like ~(163)
. Essentially, I want every bit to flip.
Is there a way to do this in PowerShell using a unary operator or, if needed, a subroutine? I would also need this to flip all the bits of the entire 32-bit address. In other words, 163 in binary is 0b10100011, but I would want the entire 32-bit container to be flipped including the 163 at the end (e.g. 0b11111......01011100).
As Bill_Stewart commented, the -bnot
(binary not or bitwise not) operator does what you want. It works in PowerShell 2.0.
Just be aware that PowerShell's default integers are generally signed, and the result of this operation will be different depending on that.
You may need to cast to one of the unsigned types to get the result you want:
-bnot ([uint32]163)