开发者

Mixing addition and subtraction with logical NOT

开发者 https://www.devze.com 2023-01-15 11:02 出处:网络
I found some exercises where you combine n-bit 2\'s complement values in different ways and simplify the output where possible. (Their practice exercises use 16-bit, but that\'s irrelevant).

I found some exercises where you combine n-bit 2's complement values in different ways and simplify the output where possible. (Their practice exercises use 16-bit, but that's irrelevant).

Eg:

!(!x&!y) == x|y

0 & y, negate the output == -1

I'm having no problem applying De Morgan's laws with the examples开发者_如何学C using AND, OR, and NOT but I am having difficulty using NOT with + and -

Eg:

!(!x+y) == x-y

!(y-1) == -y

How does NOT distribute?

Edit: responding to comments: I realize this is a bitwise NOT. My question is: in algebraic terms, how does it distribute as per algebra? Example on Wikipedia


With 2's complement numbers when you bitwise NOT them it is the same as saying the negative of the number minus 1, so !x is equivalent to -x - 1 where x can be a single variable or an expression.

Starting with !(!x+y), well !x is going to be -x - 1 so then it is !(-x - 1 + y) which becomes -(-x - 1 + y) - 1 which simplifies to x - y.

And for !(y-1), that becomes -(y - 1) - 1 = -y + 1 - 1 = -y.

0

精彩评论

暂无评论...
验证码 换一张
取 消