-sets x to 0
-sets x to !0, which is 1111 1111 1111 1111 (-1)
-sets y to !y
-adds -1 and !y, which is the same as !y-1
-flips the bits from the sum above.
In other words, we take !y, subtract 1, then flip all the bits. Anytime you subtract 1 then flip all the bits, you have the 2's complement.
So this is the 2's complement of !y. The 2's complement can also be thought of as you flip all bits, then add 1. If you flip all bits of !y you get y. Now add 1. You get y+1
(You seem to be using the distributive property on the ! bitwise operator across the sum. It's been too long since I've taken the course, so I leave it to someone else to explain why that doesn't work)
I wish the authors covered this more deeply, but I suspect their position would be that this is simply one of the things that needs to be done at a superficial level in order to fit everything that is critical into a one-semester course. Hard to argue with that.