<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>counting bits | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/counting-bits/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Mon, 11 May 2020 10:03:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>counting bits | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>A remarkable piece of C code</title>
		<link>https://learncgames.com/a-remarkable-piece-of-c-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-remarkable-piece-of-c-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 21 May 2020 23:00:31 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[counting bits]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=655</guid>

					<description><![CDATA[<p>What do you think this outputs? unsigned char c = 241; long bits = (c * 01001001001ULL &#38; 042104210421ULL) % 017; printf(&#34;Bits = %lu\n&#34;,bits); Remarkably it calculates the number of bits in c and should output &#8220;Bits = 5&#8221;. If you don&#8217;t believe me, try this program to show all 256 values and the count. [&#8230;]</p>
The post <a href="https://learncgames.com/a-remarkable-piece-of-c-code/">A remarkable piece of C code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:717,&quot;href&quot;:&quot;https:\/\/repl.it\/repls\/AzureCelebratedVideogames&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;https:\/\/replit.com\/repls\/AzureCelebratedVideogames&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<p>What do you think this outputs?</p>
<pre><code class="language-c" data-line="">unsigned char c = 241;
long bits = (c * 01001001001ULL &amp; 042104210421ULL) % 017;
printf(&quot;Bits = %lu\n&quot;,bits);
</code></pre>
<p>Remarkably it calculates the number of bits in c and should output &#8220;Bits = 5&#8221;.</p>
<p>If you don&#8217;t believe me, try this program to show all 256 values and the count. If you use c in the for loop instead of i, it never finishes. Well not with Visual C++ 2019!</p>
<pre><code class="language-c" data-line="">#include &lt;stdio.h&gt;

int main()
{
    for (int i = 0; i &lt; 256; i++){
        unsigned char c = i % 256;
        long bits = (c * 01001001001ULL &amp; 042104210421ULL) % 017;
        printf(&quot;c %d #Bits = %lu\n&quot;,c, bits);
    }
    return 0;
}</code></pre>
<p>You can try this out online on one of the various online C compilers.<br />
<img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-656" src="https://learncgames.com/wp-content/uploads/2020/05/count-bits.png" alt="Count bits" width="650" height="288" srcset="https://learncgames.com/wp-content/uploads/2020/05/count-bits.png 650w, https://learncgames.com/wp-content/uploads/2020/05/count-bits-300x133.png 300w" sizes="(max-width: 650px) 100vw, 650px" />Here&#8217;s it on <a title="Link to repl.it" href="https://repl.it/repls/AzureCelebratedVideogames" target="_blank" rel="nofollow noopener noreferrer">repl.it</a>.</p>The post <a href="https://learncgames.com/a-remarkable-piece-of-c-code/">A remarkable piece of C code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">655</post-id>	</item>
	</channel>
</rss>
