lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

index.md (746B)


      1 +++
      2 title = 'Addition & subtraction with signed integers'
      3 +++
      4 # Addition & subtraction with signed integers
      5 Just like with base-10 numbers, but you carry if you have more than the binary version of 1.
      6 
      7 To add (2’s complement): add bitwise, ignoring the leftmost carry-out.
      8 
      9 To subtract (2’s complement): for X-Y, form 2’s complement of Y and then add.
     10 
     11 ![screenshot.png](screenshot-2.png) ![screenshot.png](screenshot-1.png)
     12 
     13 An overflow happens when both terms have the same sign and the result has a different sign.
     14 
     15 In 1’s complement, the carry-out can’t be ignored — if it’s 0, the result is correct; if it’s 1, a 1 has to be added to the result.
     16 
     17 You can stick the same value into more bits by repeating the leftmost digit.