<?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: Working with bits and bitfields</title>
	<atom:link href="http://www.coranac.com/documents/working-with-bits-and-bitfields/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coranac.com</link>
	<description>my own little world</description>
	<lastBuildDate>Mon, 30 Aug 2010 15:42:13 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: cearn</title>
		<link>http://www.coranac.com/documents/working-with-bits-and-bitfields/comment-page-1/#comment-2446</link>
		<dc:creator>cearn</dc:creator>
		<pubDate>Wed, 09 Sep 2009 16:16:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.coranac.com/?page_id=50#comment-2446</guid>
		<description>I don&#039;t believe it&#039;s possible, no. I&#039;m not sure that a ten-iteration loop is that bad, though. If you must, you can grab the whole set and go through it in a binary search rather than one by one. 

If you have it, a Count Leading Zero instruction (CLZ) would help out as well. And even if you don&#039;t, there are fast algorithms out there that can do this as well.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t believe it&#8217;s possible, no. I&#8217;m not sure that a ten-iteration loop is that bad, though. If you must, you can grab the whole set and go through it in a binary search rather than one by one. </p>
<p> If you have it, a Count Leading Zero instruction (CLZ) would help out as well. And even if you don&#8217;t, there are fast algorithms out there that can do this as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cloud9ine</title>
		<link>http://www.coranac.com/documents/working-with-bits-and-bitfields/comment-page-1/#comment-2431</link>
		<dc:creator>cloud9ine</dc:creator>
		<pubDate>Thu, 03 Sep 2009 17:58:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.coranac.com/?page_id=50#comment-2431</guid>
		<description>Is there a way to use prioritized bitfields and directly retrieve the highest priority bit that is set / cleared within it?

For example say, I have a 10-bit bitfield that represents whether each of faults 0 through 9 are active now. Say fault 9 is highest priority and fault 0 is lowest. Is there a way I can just use a function and say &#039;get_highest priority_position_set_in_bitfield(bitfield)&#039; and the function will return, say, 6?

I know a loop could but I am looking for better.</description>
		<content:encoded><![CDATA[<p>Is there a way to use prioritized bitfields and directly retrieve the highest priority bit that is set / cleared within it?</p>
<p> For example say, I have a 10-bit bitfield that represents whether each of faults 0 through 9 are active now. Say fault 9 is highest priority and fault 0 is lowest. Is there a way I can just use a function and say &#8216;get_highest priority_position_set_in_bitfield(bitfield)&#8217; and the function will return, say, 6?</p>
<p> I know a loop could but I am looking for better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cearn</title>
		<link>http://www.coranac.com/documents/working-with-bits-and-bitfields/comment-page-1/#comment-2131</link>
		<dc:creator>cearn</dc:creator>
		<pubDate>Tue, 12 May 2009 13:55:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.coranac.com/?page_id=50#comment-2131</guid>
		<description>Yeah, &lt;code&gt;BF_GET()&lt;/code&gt; was wrong. As far as I can see, the rest are correct though.</description>
		<content:encoded><![CDATA[<p>Yeah, <code>BF_GET()</code> was wrong. As far as I can see, the rest are correct though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Travis H.</title>
		<link>http://www.coranac.com/documents/working-with-bits-and-bitfields/comment-page-1/#comment-2130</link>
		<dc:creator>Travis H.</dc:creator>
		<pubDate>Tue, 12 May 2009 13:09:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.coranac.com/?page_id=50#comment-2130</guid>
		<description>Some of these bit field things are wrong.

Here&#039;s a tested version:

[code lang=&quot;cpp&quot;]
/* Create a bitmask of length len */
#define BIT_MASK(len) (BIT(len)-1)

/* Create a bitfield mask of length len starting at bit start */
#define BF_MASK(start, len) ( BIT_MASK(len)&lt;&lt;(start) )

/* Prepare a bitmask for insertion or combining */
#define BF_PREP(x, start, len) (((x)&amp;BIT_MASK(len))&lt;&lt;(start)) &amp; BIT_MASK(len) )

/* Extract a bitfield of length len starting at bit start from y */
#define BF_GET(y, start, len) ( ((y)&gt;&gt;(start))&amp;BIT_MASK(len) )

/* Insert a new bitfield value x into y */
#define BF_SET(y, x, start, len) \
              (y=((y) &amp;~ BF_MASK(start, len)) &#124; BF_PREP(x, start, len))
[/code]

&lt;small&gt;&lt;b&gt;NOTE: this comment is a reconstruction after a recent DB fail&lt;/b&gt; - jv&lt;/small&gt;</description>
		<content:encoded><![CDATA[<p>Some of these bit field things are wrong.</p>
<p> Here&#8217;s a tested version:</p>
<div class="cpp">
<div class="cpp proglist" style=" "><span class="coMULTI">/* Create a bitmask of length len */</span><br /> <span class="kw1">#define</span> BIT_MASK(len) (BIT(len)-<span class="nu0">1</span>)</p>
<p> <span class="coMULTI">/* Create a bitfield mask of length len starting at bit start */</span><br /> <span class="kw1">#define</span> BF_MASK(start, len) ( BIT_MASK(len)&lt;&lt;(start) )</p>
<p> <span class="coMULTI">/* Prepare a bitmask for insertion or combining */</span><br /> <span class="kw1">#define</span> BF_PREP(x, start, len) (((x)&amp;BIT_MASK(len))&lt;&lt;(start)) &amp; BIT_MASK(len) )</p>
<p> <span class="coMULTI">/* Extract a bitfield of length len starting at bit start from y */</span><br /> <span class="kw1">#define</span> BF_GET(y, start, len) ( ((y)&gt;&gt;(start))&amp;BIT_MASK(len) )</p>
<p> <span class="coMULTI">/* Insert a new bitfield value x into y */</span><br /> <span class="kw1">#define</span> BF_SET(y, x, start, len) \<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (y=((y) &amp;~ BF_MASK(start, len)) | BF_PREP(x, start, len))</div>
</div>
<p> <small><b>NOTE: this comment is a reconstruction after a recent DB fail</b> &#8211; jv</small></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ged</title>
		<link>http://www.coranac.com/documents/working-with-bits-and-bitfields/comment-page-1/#comment-2005</link>
		<dc:creator>Ged</dc:creator>
		<pubDate>Sun, 12 Oct 2008 18:27:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.coranac.com/?page_id=50#comment-2005</guid>
		<description>Great article!</description>
		<content:encoded><![CDATA[<p>Great article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kawa</title>
		<link>http://www.coranac.com/documents/working-with-bits-and-bitfields/comment-page-1/#comment-1822</link>
		<dc:creator>Kawa</dc:creator>
		<pubDate>Fri, 30 May 2008 17:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.coranac.com/?page_id=50#comment-1822</guid>
		<description>I *HATE* bit fiddling!</description>
		<content:encoded><![CDATA[<p>I *HATE* bit fiddling!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!--
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
</head>
<body>
<p>
My database has called in sick. Please imagine some 
annoying elevator tune till he gets back.
</p>
<p>
<small>[[Doo-di-doo tooo. Dum-di-dum-di-doo-dooo.]]</small>
</p>
</body>
</html>

-->