<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Quick Java Puzzler</title>
	<atom:link href="http://www.symphonious.net/2006/09/14/quick-java-puzzler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.symphonious.net/2006/09/14/quick-java-puzzler/</link>
	<description>Living in a state of accord.</description>
	<pubDate>Fri, 09 Jan 2009 21:24:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Milo</title>
		<link>http://www.symphonious.net/2006/09/14/quick-java-puzzler/comment-page-1/#comment-32138</link>
		<dc:creator>Milo</dc:creator>
		<pubDate>Thu, 14 Sep 2006 07:02:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.symphonious.net/2006/09/14/quick-java-puzzler/#comment-32138</guid>
		<description>Gah, hit submit while checking that post.  min is -4 not -3.</description>
		<content:encoded><![CDATA[<p>Gah, hit submit while checking that post.  min is -4 not -3.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milo</title>
		<link>http://www.symphonious.net/2006/09/14/quick-java-puzzler/comment-page-1/#comment-32137</link>
		<dc:creator>Milo</dc:creator>
		<pubDate>Thu, 14 Sep 2006 06:59:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.symphonious.net/2006/09/14/quick-java-puzzler/#comment-32137</guid>
		<description>And for the nerd in me, it took me ages to understand twos-compliment so i love any chance to explain what's going on, humour me if you will:

Say we have a number system with only 3 bits using twos-compliment.  max number you get is 3, min is -3.  the bit pattern for each number is:

000   0
001   1
010   2
011   3
100 -4
101 -3
110 -2
111 -1

two's complement flips the sign on a number by inverting the bit pattern and then adding one. For example, 2 is 010.  flip the bits it becomes 101, add one you get 110, which as the table shows is -2.  To show the original problem with an example, -4 is 100.  flip the bits and you get 011, add 1 and voila, you get 100.

The other cool (i really am a geek) case is negating 0.  000 flips to 111, we add 1 and we get 1000, but since we only have 3 bits, the leading 1 is lost and we end up with 000.  So with twos-complements there are always 2 numbers that when negated will equal themself: 0 and the min.

</description>
		<content:encoded><![CDATA[<p>And for the nerd in me, it took me ages to understand twos-compliment so i love any chance to explain what&#8217;s going on, humour me if you will:</p>
<p>Say we have a number system with only 3 bits using twos-compliment.  max number you get is 3, min is -3.  the bit pattern for each number is:</p>
<p>000   0<br />
001   1<br />
010   2<br />
011   3<br />
100 -4<br />
101 -3<br />
110 -2<br />
111 -1</p>
<p>two&#8217;s complement flips the sign on a number by inverting the bit pattern and then adding one. For example, 2 is 010.  flip the bits it becomes 101, add one you get 110, which as the table shows is -2.  To show the original problem with an example, -4 is 100.  flip the bits and you get 011, add 1 and voila, you get 100.</p>
<p>The other cool (i really am a geek) case is negating 0.  000 flips to 111, we add 1 and we get 1000, but since we only have 3 bits, the leading 1 is lost and we end up with 000.  So with twos-complements there are always 2 numbers that when negated will equal themself: 0 and the min.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adrian Sutton</title>
		<link>http://www.symphonious.net/2006/09/14/quick-java-puzzler/comment-page-1/#comment-32103</link>
		<dc:creator>Adrian Sutton</dc:creator>
		<pubDate>Thu, 14 Sep 2006 01:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.symphonious.net/2006/09/14/quick-java-puzzler/#comment-32103</guid>
		<description>Yep, in twos-compliment notation, you can always go one value more negative than you can positive (ie: if you can get to +3, you can get to -4).</description>
		<content:encoded><![CDATA[<p>Yep, in twos-compliment notation, you can always go one value more negative than you can positive (ie: if you can get to +3, you can get to -4).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milo</title>
		<link>http://www.symphonious.net/2006/09/14/quick-java-puzzler/comment-page-1/#comment-32100</link>
		<dc:creator>Milo</dc:creator>
		<pubDate>Thu, 14 Sep 2006 00:51:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.symphonious.net/2006/09/14/quick-java-puzzler/#comment-32100</guid>
		<description>Oh, and its not like I figured that one out on my own, was one of the many interesting cases listed in a book I think I've mentioned before: Java™ Puzzlers: Traps, Pitfalls, and Corner Cases, by Joshua Bloch, Neal Gafter.  If you find this puzzle interesting I highly recommend the book.  It's up on safari - http://search.safaribooksonline.com - you can get a trial account for 2 weeks I think so won't even cost you anything.</description>
		<content:encoded><![CDATA[<p>Oh, and its not like I figured that one out on my own, was one of the many interesting cases listed in a book I think I&#8217;ve mentioned before: Java™ Puzzlers: Traps, Pitfalls, and Corner Cases, by Joshua Bloch, Neal Gafter.  If you find this puzzle interesting I highly recommend the book.  It&#8217;s up on safari - <a href="http://search.safaribooksonline.com" rel="nofollow">http://search.safaribooksonline.com</a> - you can get a trial account for 2 weeks I think so won&#8217;t even cost you anything.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milo</title>
		<link>http://www.symphonious.net/2006/09/14/quick-java-puzzler/comment-page-1/#comment-32097</link>
		<dc:creator>Milo</dc:creator>
		<pubDate>Thu, 14 Sep 2006 00:46:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.symphonious.net/2006/09/14/quick-java-puzzler/#comment-32097</guid>
		<description>That would be Integer.MIN_VALUE :)</description>
		<content:encoded><![CDATA[<p>That would be Integer.MIN_VALUE :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
