<?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: Interview Questions: Counting Bits</title>
	<atom:link href="http://20bits.com/articles/interview-questions-counting-bits/feed/" rel="self" type="application/rss+xml" />
	<link>http://20bits.com/articles/interview-questions-counting-bits/</link>
	<description>Driven by Data</description>
	<lastBuildDate>Wed, 28 Jul 2010 21:50:46 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: sven.hedin</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-5072</link>
		<dc:creator>sven.hedin</dc:creator>
		<pubDate>Mon, 28 Jun 2010 15:34:21 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-5072</guid>
		<description>In all codes above you used 0x1u, why not only 1 instead? I think both do the same thing.</description>
		<content:encoded><![CDATA[<p>In all codes above you used 0&#215;1u, why not only 1 instead? I think both do the same thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hrish</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-5045</link>
		<dc:creator>Hrish</dc:creator>
		<pubDate>Wed, 16 Jun 2010 08:06:03 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-5045</guid>
		<description>Just noticed that the link &lt;a href=&quot;http://20bits.com/tag/interview/&quot; rel=&quot;nofollow&quot;&gt;http://20bits.com/tag/interview/&lt;/a&gt; at the beginning of your article is broken.</description>
		<content:encoded><![CDATA[<p>Just noticed that the link <a href="http://20bits.com/tag/interview/" rel="nofollow">http://20bits.com/tag/interview/</a> at the beginning of your article is broken.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gournew</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-4946</link>
		<dc:creator>gournew</dc:creator>
		<pubDate>Thu, 08 Apr 2010 23:36:10 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-4946</guid>
		<description>Now in this case we can reduce the number of iteration..&lt;br&gt;as for example if input is 64 then the binary will be 100000&lt;br&gt;so if normal procedure used then we have to itrate 6v times in the loop&lt;br&gt;&lt;br&gt;simple steps&lt;br&gt;int count_bit(int num)&lt;br&gt;{&lt;br&gt;    count =0;&lt;br&gt;    while(num)&lt;br&gt;    {&lt;br&gt;          num=(num) &amp; (num-1);&lt;br&gt;          count++;&lt;br&gt;      }&lt;br&gt;return count;&lt;br&gt;// complete program will be  available in&lt;br&gt;//  &lt;a href=&quot;http://goursaha.freeoda.com&quot; rel=&quot;nofollow&quot;&gt;http://goursaha.freeoda.com&lt;/a&gt;&lt;br&gt;}</description>
		<content:encoded><![CDATA[<p>Now in this case we can reduce the number of iteration..<br />as for example if input is 64 then the binary will be 100000<br />so if normal procedure used then we have to itrate 6v times in the loop</p>
<p>simple steps<br />int count_bit(int num)<br />{<br />    count =0;<br />    while(num)<br />    {<br />          num=(num) &#038; (num-1);<br />          count++;<br />      }<br />return count;<br />// complete program will be  available in<br />//  <a href="http://goursaha.freeoda.com" rel="nofollow">http://goursaha.freeoda.com</a><br />}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axvpast</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-4862</link>
		<dc:creator>axvpast</dc:creator>
		<pubDate>Tue, 23 Feb 2010 03:27:57 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-4862</guid>
		<description>it is not so good answers all, because best way to solve tasks like:&lt;br&gt; We choose the routing destination based on the number of on bits in the binary representation of the routing number.&lt;br&gt;&lt;br&gt;Using VHDL :) in hardware level (like CRC32 computation). All can be done in one instruction like it do real routers :)</description>
		<content:encoded><![CDATA[<p>it is not so good answers all, because best way to solve tasks like:<br /> We choose the routing destination based on the number of on bits in the binary representation of the routing number.</p>
<p>Using VHDL :) in hardware level (like CRC32 computation). All can be done in one instruction like it do real routers :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mohdhussain</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-4833</link>
		<dc:creator>mohdhussain</dc:creator>
		<pubDate>Wed, 03 Feb 2010 03:47:20 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-4833</guid>
		<description>bits of accounts questions answers</description>
		<content:encoded><![CDATA[<p>bits of accounts questions answers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reuben</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-2492</link>
		<dc:creator>Reuben</dc:creator>
		<pubDate>Thu, 08 May 2008 00:16:13 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-2492</guid>
		<description>I&#039;m surprised the bit counting in parallel code snippet wasn&#039;t included in this post too -- I thought it was a classic.  Here&#039;s a link to the algorithm (in response to roi):

http://www.cs.utk.edu/~vose/c-stuff/bithacks.html#CountBitsSetParallel

This version doesn&#039;t use a for loop so that you can clearly see the c*log_2{n} == c*5 steps (for n=32).  Easily changed to accomodate counting bits set for 64 bit integers of course.

Another interesting solution, which is faster than the naive solution only for integers where the bits set are few, is here:

http://www.cs.utk.edu/~vose/c-stuff/bithacks.html#CountBitsSetKernighan</description>
		<content:encoded><![CDATA[<p>I&#8217;m surprised the bit counting in parallel code snippet wasn&#8217;t included in this post too &#8212; I thought it was a classic.  Here&#8217;s a link to the algorithm (in response to roi):</p>
<p><a href="http://www.cs.utk.edu/~vose/c-stuff/bithacks.html#CountBitsSetParallel" rel="nofollow">http://www.cs.utk.edu/~vose/c-stuff/bithacks.html#CountBitsSetParallel</a></p>
<p>This version doesn&#8217;t use a for loop so that you can clearly see the c*log_2{n} == c*5 steps (for n=32).  Easily changed to accomodate counting bits set for 64 bit integers of course.</p>
<p>Another interesting solution, which is faster than the naive solution only for integers where the bits set are few, is here:</p>
<p><a href="http://www.cs.utk.edu/~vose/c-stuff/bithacks.html#CountBitsSetKernighan" rel="nofollow">http://www.cs.utk.edu/~vose/c-stuff/bithacks.html#CountBitsSetKernighan</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roi</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-2012</link>
		<dc:creator>roi</dc:creator>
		<pubDate>Wed, 30 Apr 2008 20:30:55 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-2012</guid>
		<description>I see that Wordpress didn&#039;t like it. Another attempt at the punchline:

&lt;pre&gt;
for ( i = 0; (1&lt;&lt;i) &lt; 32; i++) n = ((n &amp; ~masks[i]) &gt; &gt; (1&lt;&lt;i)) + (n &amp; masks[i]);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I see that Wordpress didn&#8217;t like it. Another attempt at the punchline:</p>
<pre>
for ( i = 0; (1&lt;&lt;i) &lt; 32; i++) n = ((n &amp; ~masks[i]) &gt; &gt; (1&lt;&lt;i)) + (n &amp; masks[i]);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: roi</title>
		<link>http://20bits.com/articles/interview-questions-counting-bits/comment-page-1/#comment-2009</link>
		<dc:creator>roi</dc:creator>
		<pubDate>Wed, 30 Apr 2008 20:19:02 +0000</pubDate>
		<guid isPermaLink="false">http://20bits.com/?p=108#comment-2009</guid>
		<description>There&#039;s a cuter, log n algorithm:

&lt;pre&gt;
int bitcount(unsigned int n) {
    unsigned int i, masks[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
    for ( i = 0; (1&lt;&lt;i) &gt; (1&lt;&lt;i)) + (n &amp; masks[i]);
    return n;
}
&lt;/pre&gt;
(I hope it survives wordpress&#039; munging)

Creating the bitmasks programatically, to make it independent of int size, is left as a trivial exercise for the reader.</description>
		<content:encoded><![CDATA[<p>There&#8217;s a cuter, log n algorithm:</p>
<pre>
int bitcount(unsigned int n) {
    unsigned int i, masks[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
    for ( i = 0; (1&lt;&lt;i) &gt; (1&lt;&lt;i)) + (n &amp; masks[i]);
    return n;
}
</pre>
<p>(I hope it survives wordpress&#8217; munging)</p>
<p>Creating the bitmasks programatically, to make it independent of int size, is left as a trivial exercise for the reader.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
