How can I determine if overflow occured using AND OR NOT and XOR?

后端 未结 3 955
甜味超标
甜味超标 2021-01-25 12:02

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

3条回答
  •  执笔经年
    2021-01-25 12:47

    Numbers are ABCD and EFGH, ^ is AND, | is OR.

    (A^E) | (B^F^(A|E)) | (C^G^(B|F)^(A|E)) | (D^H^(C|G)^(B|F)^(A|E))

    I'm sure you can see the pattern there, so a recursive solution is pretty easy for numbers with more bits.

提交回复
热议问题