<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Overflow mathematics</title>
		<link>http://forums.leaflabs.com/topic.php?id=74060</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:17:34 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=74060" rel="self" type="application/rss+xml" />

		<item>
			<title>pyrohaz on "Overflow mathematics"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74060#post-104797</link>
			<pubDate>Sun, 20 Oct 2013 07:22:33 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">104797@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Oh! I didn't know that was actually how the twos complement is calculated, I knew of the twos complement obviously but thats awesome! There are so many clever engineers in this works, past and present. We've done about binary addition and subtraction through 2's complement (and why signed and offset methods don't work either). I meant 256 in the earlier post come to think of it but thank you for the clarification. Digital electronics is great!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Overflow mathematics"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74060#post-104795</link>
			<pubDate>Sat, 19 Oct 2013 10:09:15 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">104795@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;pyrohaz - if we work through your proposal:&#60;/p&#62;
&#60;p&#62;A = 200&#60;br /&#62;
B = 40&#60;/p&#62;
&#60;p&#62;result = A - B&#60;br /&#62;
          = 200 + (255-40)&#60;br /&#62;
          = 200 (1100100) + 215 (11010111)&#60;br /&#62;
          = 415 (110011111)&#60;br /&#62;
masked to 8 bits = 10011111 = 159&#60;br /&#62;
which is incorrect.&#60;/p&#62;
&#60;p&#62;The number 215 is suspicious.&#60;br /&#62;
In binary, the bottom binary digit (bit) of a number determines if the number is odd or even.&#60;br /&#62;
Adding or subtracting two even numbers always produces an even number, so 200-40 must be even.&#60;br /&#62;
The operation 255-40 converts an even number to an odd number, so it is either wrong, or there are other steps missing from the algorithm. &#60;/p&#62;
&#60;p&#62;As mlundinse has explained, taking the two's complement, is 256-x, and that does produce the correct binary value.&#60;br /&#62;
Geting the two's complement is straightforward, and does not need the subtraction operation.&#60;br /&#62;
Two's complement: flip all the bits and add one.&#60;br /&#62;
Example 40: (00101000)&#60;br /&#62;
 -&#38;gt; flip all the bits (1's complement) = 11010111&#60;br /&#62;
 -&#38;gt; add 1 to 11010111 = 11011000 (216)&#60;br /&#62;
Those operations are easy to implement (there must be an add implemented :-)&#60;/p&#62;
&#60;p&#62;An important point which needs reinforcing is, the electronics to do the bit operations on the numbers for signed and unsigned binary addition is the same. The difference is how carry or overflow is interpreted. &#60;/p&#62;
&#60;p&#62;So the nifty part is subtraction &#60;strong&#62;is&#60;/strong&#62; addition using the two's complement of the subtrahend, even for unsigned arithmetic.&#60;br /&#62;
Addition is the same for signed and unsigned numbers, the difference is the interpretation of the carry and top bit (sign) to identify overflow.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "Overflow mathematics"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74060#post-104794</link>
			<pubDate>Sat, 19 Oct 2013 05:11:50 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">104794@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;First you should add 216 = 256-40 since the overflow subtracts 256.&#60;/p&#62;
&#60;p&#62;Yes this is really the difference between signed and unsigned 8 bit numbers&#60;/p&#62;
&#60;p&#62;The binary representation of unsigned 216 = signed -40 = 11011000'b&#60;/p&#62;
&#60;p&#62;So this can, and it is, used but if used carelessly can add a lot of confusion.&#60;br /&#62;
For instance if you are playing with 8 bit values on a 32 bit machine, can you&#60;br /&#62;
be sure how the compiler/processor handles the overflow ?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Overflow mathematics"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74060#post-104787</link>
			<pubDate>Fri, 18 Oct 2013 16:24:49 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">104787@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey guys,&#60;/p&#62;
&#60;p&#62;This isn't really a question based on the maple, just a question based on digital logic. I was in a lecture earlier this week day dreaming when the lecturer was talking about 2's complement and I thought to myself why overflow mathematics hasn't been thought of? I know that obviously this doesn't allow for numbers below 0 but it seems really easy to implement in logic.&#60;/p&#62;
&#60;p&#62;For example, say you have an 8 bit register and you're currently on 200 yet you want to subtract 40 to say 160, couldnt you surely add 215? Working this out through A-B = C&#60;/p&#62;
&#60;p&#62;A = Number you want&#60;br /&#62;
B = Number you have&#60;/p&#62;
&#60;p&#62;A+(255-B). Obviously where 255 is the MSB number of the bit depth of the system?&#60;/p&#62;
&#60;p&#62;Any ideas?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
