lectures.alex.balgavy.eu

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

Addition & subtraction with signed integers.html (1737B)


      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      3 <html><head><link rel="stylesheet" href="sitewide.css" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 6.13.1 (455785)"/><meta name="altitude" content="-1.015779376029968"/><meta name="author" content="Alex Balgavy"/><meta name="created" content="2017-12-05 4:15:58 PM +0000"/><meta name="latitude" content="52.33179173588104"/><meta name="longitude" content="4.869868269056413"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2017-12-05 9:49:51 PM +0000"/><title>Addition &amp; subtraction with signed integers</title></head><body><div>Just like with base-10 numbers, but you carry if you have more than the binary version of 1.<br/></div><div>To add (2’s complement): add bitwise, ignoring the leftmost carry-out.</div><div>To subtract (2’s complement): for X-Y, form 2’s complement of Y and then add.</div><div><br/></div><div><img src="Addition%20&amp;%20subtraction%20with%20signed%20integers.resources/screenshot.png" height="159" width="420"/>         <img src="Addition%20&amp;%20subtraction%20with%20signed%20integers.resources/screenshot_1.png" height="117" width="143"/><br/></div><div><br/></div><div>An overflow happens when both terms have the same sign and the result has a different sign.</div><div>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.</div><div>You can stick the same value into more bits by repeating the leftmost digit.</div></body></html>