<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Integer Based Bit Manipulation - C#</title><link>http://weblogs.asp.net/bdill/archive/2008/01/06/integer-based-bit-manipulation-c.aspx</link><description>As a follow up to my post from yesterday , here is the C# extension version of the integer bit manipulation.&amp;#160; In order to facilitate the code I post, I have created a Codeplex project.&amp;#160; The project name is Pickle , from my last name.&amp;#160; It</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Integer Based Bit Manipulation - C#</title><link>http://weblogs.asp.net/bdill/archive/2008/01/06/integer-based-bit-manipulation-c.aspx#5570393</link><pubDate>Tue, 08 Jan 2008 17:49:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5570393</guid><dc:creator>ReSc</dc:creator><author>ReSc</author><description>&lt;p&gt;YZ: Nope it can&amp;#39;t, you missed the bit about ensuring there is only 1 bit set ;-)&lt;/p&gt;
&lt;p&gt;System.Collections.Specialized.BitVector32 would be the pre-cooked solution.&lt;/p&gt;
&lt;p&gt;anyways, in the usage code snippet given i would be much happier if an enum with the flags attribute was used like:&lt;/p&gt;
&lt;p&gt;[Flags]&lt;/p&gt;
&lt;p&gt;public enum Permissions &lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;None = 0,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Read = 1,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Write = 2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Delete = 4, &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;ReadWrite = Read | Write,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Admin = ReadWrite | Delete,&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;then you could do:&lt;/p&gt;
&lt;p&gt;Permissions p = Permissions.Read | Permissions.Write&lt;/p&gt;
&lt;p&gt;testing would be a but ugly though:&lt;/p&gt;
&lt;p&gt;bool readable = (p &amp;amp; Permissions.Read) == Permissions.Read;&lt;/p&gt;
&lt;p&gt;But that could be fixed a few finely crafted extension methods...&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5570393" width="1" height="1"&gt;</description></item><item><title>re: Integer Based Bit Manipulation - C#</title><link>http://weblogs.asp.net/bdill/archive/2008/01/06/integer-based-bit-manipulation-c.aspx#5563909</link><pubDate>Mon, 07 Jan 2008 15:26:42 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5563909</guid><dc:creator>YZ</dc:creator><author>YZ</author><description>&lt;p&gt;Interesting.&lt;/p&gt;
&lt;p&gt;How about this:&lt;/p&gt;
&lt;p&gt;return state ? (target | bit) : (target &amp;amp; ~bit);&lt;/p&gt;
&lt;p&gt;This single line can replace your whole SetBit method :-)&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5563909" width="1" height="1"&gt;</description></item></channel></rss>