How to change the sign of int using bitwise operators? Obviously we can use x*=-1 or x/=-1. Is there any fastest way of doing this?
x*=-1
x/=-1
I did a sm
Java uses Complement Two representation. In order to change a sign, it means you must do a bitwise negation (it would be equivalent to xor with FFFF) and add 1.
x = ~x + 1;
I am almost sure that -x is, if anything, faster than that.
-x