When I give to a variable such value: e = 17|-15; , I get -15 as an answer after compiling.I can’t understand what arithmetic c++ uses. How does it perform a bit-wise OR operation on negative decimals?
When I give to a variable such value: e = 17|-15; , I get
Share
It’s just doing the operation on the binary representations of your numbers. In your case, that appears to be two’s complement.
As you can see, the bitwise
ORof those two numbers is still-15.In your comments above, you indicated that you tried this with the two’s complement representations, but you must have done something wrong. Here’s the step by step: