Do we ignore overflow in Two's Complement

前端 未结 2 912
时光取名叫无心
时光取名叫无心 2021-01-24 10:31

I\'m trying to wrap my head around overflow within twos complement for example say I\'m trying to take away these two binary numbers: 1111 1000 0100 - 010 111 001 000

I

2条回答
  •  孤街浪徒
    2021-01-24 11:22

    From Wikipedia's article on 2's complement in the section on addition at https://en.wikipedia.org/wiki/Two%27s_complement#Addition, my understanding is that carry beyond the given (fixed) bit length (to the left) can be ignored but not overflow as determined when the leftmost two bits of the carry are different. The article shows how to maintain a carry row so as to tell if there was overflow and here is a simple example in the same style:

    In 4 bit 2's complement -2 is 1110 and +3 is 0011 so

    11110  carry 
     1110  -2
    +0011  +3
     ----
    10001  which is 0001 or simply 1 ignoring the carry in bit 5 and is 
           safe since the leftmost two bits in the carry row are identical
    

提交回复
热议问题