-4 & -5 = -8 // How?
-4 & 5 = 4 // How?
I need an explanation for how the above results can be reached. I have no difficulties in solving with positive integers.
-4 & -5 = -8 // How?
-4 & 5 = 4 // How?
I need an explanation for how the above results can be reached. I have no difficulties in solving with positive integers.
Let's see how numbers are representing:
positive four 0100
negative four 1100
positive five 0101
negative five 1011
negative eight 1000
If you try to do and
operation manual, you get a result like this:
1100 (-4) & 1011 (-5) = 1000 (-8)
1100 (-4) & 0101 (5) = 0100 (4)
Here you can read more about this.
Just convert the integers to their binary representation (for negative integers, use two's complement) and run the bit-wise AND: