We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I see there are (bitwise AND) and (bitwise OR):
int b=41; int a=33; int c = a&b; println(binary(b,8)); println(binary(a,8)); println(binary(c,8)); int d = a | b;
Are there any ways of combining these with (!) to make nor and nand operations ? ( other than using a charAt loop). What I want to do is XOR two numbers to invert one to its binary opposite.
10101010
01010101 result
something like b = ! b. (which doesn't work). Thinking maybe the syntax is just eluding me. Seems this must exist in Java.
Answers
OK...I found it. b=b^a; Thanks guys.
Also there is the ~ operator which flips all the bits
~b == -(b+1)
b = b^a;
->b ^= a;
>-)