I\'m trying to use only AND OR XOR and NOT to determine whether adding 2 binary number made of 4 bits will overflow. I know, for example, that something like 1100 + 0100 will wi
I think this will work, using no loops or shifts. But its ugly:
if ( (a & 0x8) && (b & 0x8) || (((a & 0x8) || (b & 0x8)) && ((a & 0x4) && (b & 0x4))) || (((a & 0x8) || (b & 0x8)) && ((a & 0x4) || (b & 0x4)) && ((a & 0x2) && (b & 0x2))) || (((a & 0x8) || (b & 0x8)) && ((a & 0x4) || (b & 0x4)) && ((a & 0x2) || (b & 0x2)) && ((a & 0x1) && (b & 0x1))) ) { // overflow }