<?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: Hacker&#8217;s Delight</title>
	<atom:link href="http://entland.homelinux.com/blog/2008/11/04/hackers-delight/feed/" rel="self" type="application/rss+xml" />
	<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/</link>
	<description>Code, 3D, Games, Linux and much more...</description>
	<lastBuildDate>Mon, 09 Nov 2009 03:12:38 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rickyah</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166631</link>
		<dc:creator>Rickyah</dc:creator>
		<pubDate>Thu, 06 Nov 2008 11:21:39 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166631</guid>
		<description>Sorry Liam, i totally misunderstood you :(</description>
		<content:encoded><![CDATA[<p>Sorry Liam, i totally misunderstood you <img src='http://entland.homelinux.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166624</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Wed, 05 Nov 2008 17:21:09 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166624</guid>
		<description>Just typing that out quickly I have missed a set of parenthesis 
return x ? (x &amp; (x - 1)) == 0 : false;</description>
		<content:encoded><![CDATA[<p>Just typing that out quickly I have missed a set of parenthesis<br />
return x ? (x &amp; (x &#8211; 1)) == 0 : false;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ent</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166623</link>
		<dc:creator>ent</dc:creator>
		<pubDate>Wed, 05 Nov 2008 17:20:31 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166623</guid>
		<description>Liam is right,

That function is not exactly correct because is returning true for zero (zero is not a power of two).

So, rename the function to IsPower2OrZero() or add to that function the check against zero.

Sorry for the bug.</description>
		<content:encoded><![CDATA[<p>Liam is right,</p>
<p>That function is not exactly correct because is returning true for zero (zero is not a power of two).</p>
<p>So, rename the function to IsPower2OrZero() or add to that function the check against zero.</p>
<p>Sorry for the bug.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166622</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Wed, 05 Nov 2008 17:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166622</guid>
		<description>RickyAH thanks for your concern about me being unable to read code, but I fully understand it and understand the floor in the solution.

bool IsPow2(int x)
{
return x ? x &amp; (x - 1) == 0 : false;
}
bool IsPow2_org(int x)
{
return (((x) &amp; ((x) - 1)) == 0);
}
#include 
int main()
{
	int i = 0;
	std::cout &lt;&lt;IsPow2(i) &lt;&lt;&quot; &quot; &lt;&lt;IsPow2_org(i);
}</description>
		<content:encoded><![CDATA[<p>RickyAH thanks for your concern about me being unable to read code, but I fully understand it and understand the floor in the solution.</p>
<p>bool IsPow2(int x)<br />
{<br />
return x ? x &amp; (x &#8211; 1) == 0 : false;<br />
}<br />
bool IsPow2_org(int x)<br />
{<br />
return (((x) &amp; ((x) &#8211; 1)) == 0);<br />
}<br />
#include<br />
int main()<br />
{<br />
	int i = 0;<br />
	std::cout &lt;&lt;IsPow2(i) &lt;&lt;&#8221; &#8221; &lt;&lt;IsPow2_org(i);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RickyAH</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166621</link>
		<dc:creator>RickyAH</dc:creator>
		<pubDate>Wed, 05 Nov 2008 16:51:43 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166621</guid>
		<description>Liam I think you misunderstood the code abobe.

A power of two number express in binary ALWAYS has exactly ONE bit equal to 1:
2 = 0010
4 = 0100
8 = 1000
...

take that number and the previous:
1 = 0001
3 = 0011
7 = 0111

Perform an &#039;and&#039; bit operation:
0010 &amp; 0001 == 0000
0100 &amp; 0011 == 0000
1000 &amp; 0111 == 0000

For any number not power of two, e.g. 7 the result is not zero:
0111 &amp; 0110 = 0110 == 6 != 0</description>
		<content:encoded><![CDATA[<p>Liam I think you misunderstood the code abobe.</p>
<p>A power of two number express in binary ALWAYS has exactly ONE bit equal to 1:<br />
2 = 0010<br />
4 = 0100<br />
8 = 1000<br />
&#8230;</p>
<p>take that number and the previous:<br />
1 = 0001<br />
3 = 0011<br />
7 = 0111</p>
<p>Perform an &#8216;and&#8217; bit operation:<br />
0010 &amp; 0001 == 0000<br />
0100 &amp; 0011 == 0000<br />
1000 &amp; 0111 == 0000</p>
<p>For any number not power of two, e.g. 7 the result is not zero:<br />
0111 &amp; 0110 = 0110 == 6 != 0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166619</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Wed, 05 Nov 2008 15:44:31 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166619</guid>
		<description>Is zero really a power of two?</description>
		<content:encoded><![CDATA[<p>Is zero really a power of two?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickyah</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166618</link>
		<dc:creator>Rickyah</dc:creator>
		<pubDate>Wed, 05 Nov 2008 08:25:53 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166618</guid>
		<description>I&#039;ve seen that code before, but as a macro. It was in a classroom :)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve seen that code before, but as a macro. It was in a classroom <img src='http://entland.homelinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ent</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166610</link>
		<dc:creator>ent</dc:creator>
		<pubDate>Tue, 04 Nov 2008 14:59:31 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166610</guid>
		<description>bool IsPow2(int x)
{
    return (((x) &amp; ((x) - 1)) == 0);
}</description>
		<content:encoded><![CDATA[<p>bool IsPow2(int x)<br />
{<br />
    return (((x) &#038; ((x) &#8211; 1)) == 0);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zalo</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166609</link>
		<dc:creator>Zalo</dc:creator>
		<pubDate>Tue, 04 Nov 2008 13:42:52 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166609</guid>
		<description>Does this book tell how to enter into the FBI or the NASA computers? :D</description>
		<content:encoded><![CDATA[<p>Does this book tell how to enter into the FBI or the NASA computers? <img src='http://entland.homelinux.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://entland.homelinux.com/blog/2008/11/04/hackers-delight/comment-page-1/#comment-166608</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Tue, 04 Nov 2008 11:57:35 +0000</pubDate>
		<guid isPermaLink="false">http://entland.homelinux.com/blog/?p=114#comment-166608</guid>
		<description>O dear that is multiple not power of lol.
I suspect it would use the same type of logic thought, just testing the upper bit with the rest zeroed out.</description>
		<content:encoded><![CDATA[<p>O dear that is multiple not power of lol.<br />
I suspect it would use the same type of logic thought, just testing the upper bit with the rest zeroed out.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
