<story><title>Bit Twiddling Hacks (2005)</title><url>https://graphics.stanford.edu/~seander/bithacks.html</url></story><parent_chain></parent_chain><comment><author>byuu</author><text>Just a fair warning as someone who has made extensive use of this page in the past: many of these hacks often end up slower these days on modern CPUs than naive approaches. Especially the no-branch and no-multiply math ops.&lt;p&gt;As always, be sure to performance test your code if you&amp;#x27;re getting into obfuscating your algorithms to boost speeds.&lt;p&gt;That said, there are still plenty of real gems in there. And on that note, here&amp;#x27;s one of my favorite bit-twiddling hacks:&lt;p&gt;&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;webcache.googleusercontent.com&amp;#x2F;search?q=cache:www.slack.net&amp;#x2F;~ant&amp;#x2F;info&amp;#x2F;rgb_clamped_add.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;webcache.googleusercontent.com&amp;#x2F;search?q=cache:www.sla...&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;webcache.googleusercontent.com&amp;#x2F;search?q=cache:www.slack.net&amp;#x2F;~ant&amp;#x2F;info&amp;#x2F;rgb_clamped_sub.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;webcache.googleusercontent.com&amp;#x2F;search?q=cache:www.sla...&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;webcache.googleusercontent.com&amp;#x2F;search?q=cache:www.slack.net&amp;#x2F;~ant&amp;#x2F;info&amp;#x2F;rgb_mixing.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;webcache.googleusercontent.com&amp;#x2F;search?q=cache:www.sla...&lt;/a&gt;&lt;p&gt;(these functions are for RGB555, but you can easily extend these to RGB888 ops.)</text></comment>
<story><title>Bit Twiddling Hacks (2005)</title><url>https://graphics.stanford.edu/~seander/bithacks.html</url></story><parent_chain></parent_chain><comment><author>esneider</author><text>I wrote that algorithm! A year later I found Hacker&amp;#x27;s delight, a wonderful book that had a much &amp;quot;faster&amp;quot; version of the same algorithm (less ops).&lt;p&gt;For anyone interested in this kind of things, you should go read that book. It actually is a delight.</text></comment>