1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need clarification regarding carry and overflow bit

  1. Nov 18, 2014 #1
    I'm trying to understand carry & overflow bits. Carry seems pretty easy - If I'm not mistaken, if you carry on your last bit into a bit that you don't have, the carry flag is set to 1.

    For overflow, I referred to another previous thread on here, of which one of the posters recommended the thread-starter look at the following link:

    http://teaching.idallen.com/dat2343/00s/overflow.txt

    This was very helpful to me, by clarifying that the overflow bit is the exclusive or (XOR), and is set to 1 when either (but not both) of the last bit or carry bit has a 1 carried into it. When they both have a 1 carried into them, it is set to 0.

    I feel like I understand how to determine the overflow bit, but I don't understand what it means. The carry bit is easy: you are adding two numbers, and just don't have enough room (enough bits), so you don't get an accurate representation of the number. Just trying to get the same understanding for the overflow bit.

    Thanks in advance for the help.
     
  2. jcsd
  3. Nov 18, 2014 #2

    jedishrfu

    Staff: Mentor

  4. Nov 18, 2014 #3

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    Carry is mainly used for unsigned integers, overflow is something similar for signed integers.

    If you add 0100 + 0101 (let's use4 bits here), you expect a positive result because both numbers are positive. Simply putting them into your CPU will give 1001, however - that number is negative. The carry bit is not set (as both numbers are positive) but the first bit got set -> overflow.

    In the same way, adding two negative numbers should give a negative result.
    Adding 1100 and 1100 gives (1)0100 where (1) is carry - a positive result! Carry bit is set, but the first bit is not -> overflow

    The two cases for subtraction can be studied in the same way.
     
  5. Nov 18, 2014 #4

    rcgldr

    User Avatar
    Homework Helper

    Carry is set for unsigned addition. For unsigned subtraction, it's usually a "borrow" bit, but on some processors it's the "not borrow" bit.

    Overflow is for signed addition or subtraction, and indicates that the sign of the result is wrong due to overflow (addition) or underflow (subtraction). For a signed or unsigned multiply with a double register product, overflow isn't possible. For a signed or unsigned divide with a double register dividend and single register quotient, the quotient can overflow (including division by 0).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Need clarification regarding carry and overflow bit
  1. I need help regarding (Replies: 2)

Loading...