<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://community.opensourcedotnet.info/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>Chris on Computers</title><link>http://community.opensourcedotnet.info/blogs/computer/default.aspx</link><description>Various thoughts about computers, software and electronics engineering</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Encrypt local mail folders and the desktop search index</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2007/08/25/EncryptDesktopSearchIndexAndMailFolders.aspx</link><pubDate>Sat, 25 Aug 2007 18:10:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:55825</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=55825</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2007/08/25/EncryptDesktopSearchIndexAndMailFolders.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m using &lt;a href="http://www.truecrypt.org/"&gt;TrueCrypt&lt;/a&gt; to encrypt all kind of files on my computer (and on all external harddrives and most USB thumbdrives) for quite some time now and I really like it. On the PC I have a set of data I want to have encrypted but that I always need, so I&amp;#39;ve configured it to automatically mount it as &lt;span style="font-weight:bold;"&gt;X:\&lt;/span&gt; after login (that is, I just have to enter my password, hit enter and forget about it). One of this kind of data is the web browser bookmarks, history and cache. Luckily the &lt;a href="http://www.mozilla-europe.org/de/products/firefox/"&gt;Firefox&lt;/a&gt; browser allows you to store the profile wherever you want, so I simply store it on that virtual drive &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt; mentioned before.&lt;/p&gt;&lt;p&gt;Desktop Search is very useful (be it Google Desktop or Microsoft Desktop Search or whatever). However, what&amp;#39;s the point of encrypting files when they&amp;#39;re full-text indexed to some unencrypted location anyway. Hence I want this index to be stored on that encrypted drive &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt; too.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Issue:&lt;/span&gt;&lt;span style="text-decoration:underline;"&gt; &lt;/span&gt;The Windows Desktop Search service starts before I can enter the password and mount &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt;. If it can&amp;#39;t access the index, it automatically starts generating a new index at the default (and unencrypted) location. So I need some way of delaying the service start. &lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition I also want my local mail folder encrypted on &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt;. Similar to Firefox, the Mozilla email client &lt;a href="http://www.mozilla-europe.org/de/products/thunderbird/"&gt;Thunderbird&lt;/a&gt; allows my to store the profile wherever I want, so I chose to store it directly on &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt;. However, I also use Outlook 2007, and there it&amp;#39;s not that simple:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Issue:&lt;/span&gt; While Outlook 2007 allows you to store the main post folder wherever you want, for some yet unknown reason you can&amp;#39;t move IMAP or Exchange data folders.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Luckily there is a workaround for both issues, although it&amp;#39;s not trivial and involves some coding. Here&amp;#39;s what I did, let me know if you have a better solution (the NTFS built-in encryption is no option for me), or if you&amp;#39;re interested in the code:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Change the Search Index Service to start manually (instead of automatically)&lt;/li&gt;&lt;li&gt;Write a small windows service that starts automatically and checks all few seconds whether &lt;span style="font-weight:bold;"&gt;X &lt;/span&gt;is mounted. If it is, it stops further checking and starts the Search Index Service.&lt;/li&gt;&lt;li&gt;Move all files from the outlook data folder (something like Documents and Settings\..\Local Settings\Application Data\Microsoft\Office) to a new folder in &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt; and delete this Outlook folder&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Have the small windows service (from point 2) create an &lt;a href="http://www.codeproject.com/cs/files/JunctionPointsNet.asp"&gt;NTFS Junction&lt;/a&gt; (aka symlink) in place of the just deleted Outlook folder, and point it to the new directory in &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt;, as soon as &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt; is mounted; and remove this junction again once the service stops. This makes Outlook 2007 think the files are still where it expects it, but in reality they&amp;#39;re on &lt;span style="font-weight:bold;"&gt;X&lt;/span&gt; instead.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=55825" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/NTFS/default.aspx">NTFS</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/EMail/default.aspx">EMail</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Encryption/default.aspx">Encryption</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/SSL/default.aspx">SSL</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Windows/default.aspx">Windows</category></item><item><title>Capture Keyboard Input in WPF</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2007/05/08/capture-keyboard-input-in-wpf.aspx</link><pubDate>Tue, 08 May 2007 11:17:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:55735</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=55735</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2007/05/08/capture-keyboard-input-in-wpf.aspx#comments</comments><description>&lt;p&gt;In case you every need to capture some keyboard input&amp;nbsp;similar to a TextBox&amp;nbsp;but without a&amp;nbsp;TextBox (hence you also want to capture input that - on some keyboard layouts - need a secondary key to type (like % on my layout = Shift+5), but don&amp;#39;t care whether the user presses special keys like&amp;nbsp;Shift or Ctrl, or&amp;nbsp;whether the num block was used to enter a number): Don&amp;#39;t try to start with KeyDown or KeyUp, they won&amp;#39;t help much. Instead, register a text input handler on the TextCompositonManager:&lt;/p&gt;
&lt;div style="margin:0px;font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;
&lt;div style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;TextCompositionManager.AddTextInputHandler(&lt;span class="keyword"&gt;this&lt;/span&gt;,&lt;img src="http://www.zedilabs.com/wrapglyph.png" style="vertical-align:bottom;" alt="wrap glyph" /&gt;&lt;br /&gt;new&amp;nbsp;TextCompositionEventHandler(OnTextComposition));&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;...and then simply use the event handler argument&amp;#39;s Text property:&lt;/p&gt;
&lt;div style="margin:0px;font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;
&lt;div style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;&lt;span class="keyword"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;void&lt;/span&gt;&amp;nbsp;OnTextComposition(&lt;span class="keyword"&gt;object&lt;/span&gt;&amp;nbsp;sender,&lt;img src="http://www.zedilabs.com/wrapglyph.png" style="vertical-align:bottom;" alt="wrap glyph" /&gt;&lt;br /&gt;TextCompositionEventArgs&amp;nbsp;e)&amp;nbsp;&lt;br /&gt;{&lt;/div&gt;
&lt;div style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string key = e.Text;&lt;/div&gt;
&lt;div style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/div&gt;
&lt;div style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;,Courier,monospace;"&gt;}&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And you get the keyboard layout and system key tracking for free.&lt;/p&gt;
&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=55735" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Bits+and+Bytes/default.aspx">Bits and Bytes</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/WPF/default.aspx">WPF</category></item><item><title>How to get listed on the great chinese firewall?</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2007/03/08/How-to-get-listed-on-the-great-chinese-firewall_3F00_.aspx</link><pubDate>Thu, 08 Mar 2007 00:06:19 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:55598</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=55598</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2007/03/08/How-to-get-listed-on-the-great-chinese-firewall_3F00_.aspx#comments</comments><description>&lt;p&gt;My server is currently being "attacked" by a chinese&amp;nbsp;computer at&amp;nbsp;&lt;strong&gt;220.173.30.198&lt;/strong&gt;, what resolves to - you guessed right - China Telecom:&lt;/p&gt;&lt;pre&gt;netname:      CHINANET-GX
descr:        CHINANET guangxi province network
descr:        China Telecom
descr:        No.31,jingrong street
descr:        Beijing 100032&lt;/pre&gt;
&lt;p&gt;It simply &lt;strike&gt;downloads&lt;/strike&gt; &lt;em&gt;tried to download (until I blocked it on IP protocol level&lt;/em&gt;) some of my open source packages multiple times per second, more than 100'000 times up to now. It's only from one single IP and therefore easy to block, and it generated only about 3 GB extra traffic so far, so it's not really a problem. Most likely&amp;nbsp;a horribly&amp;nbsp;badly written bot ...&lt;/p&gt;
&lt;p&gt;Nevertheless: How to easily get onto the great chinese firewall? What do you have to publish on your server? Would easily prevent both spam and such annoyance... ;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why exactly these files?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I already observed something like this maybe a year ago, but expected a download manager then, that was&amp;nbsp;in some way incompatible with the way&amp;nbsp;CommunityServer&amp;nbsp;handles downloads (other than when I'd simply put them directly into an IIS folder).&lt;/p&gt;
&lt;p&gt;What caught my eye was the HTTP Range attribute (is this correct HTTP with the trailing dash?), and the (clearly faked) User-Agent of course. And why does it disallow caches?&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;GET /cs/files/folders/670/download.aspx HTTP/1.1&lt;br&gt;...&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;br&gt;User-Agent: Mozilla/4.0 (compatible; &lt;font color="#ff0000"&gt;MSIE 5.00; Windows 98&lt;/font&gt;)&lt;br&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;Range: bytes=148681-&lt;/font&gt;&lt;/strong&gt;&lt;br&gt;Pragma: &lt;font color="#ff0000"&gt;no-cache&lt;/font&gt;&lt;br&gt;Cache-Control: &lt;font color="#ff0000"&gt;no-cache&lt;/font&gt;&lt;br&gt;Connection: close&lt;/font&gt;
&lt;p&gt;Does CommunityServer maybe have a problem with ranges and download resumes? Is this just a badly written spider/grabber that just hangs there because of some incompatibility? Well, I guess not ...&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=55598" width="1" height="1"&gt;</description></item><item><title>Lock down your own .NET Library Assemblies</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2007/03/05/Lock-down-your-own-.NET-Library-Assemblies.aspx</link><pubDate>Mon, 05 Mar 2007 10:35:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:55597</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=55597</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2007/03/05/Lock-down-your-own-.NET-Library-Assemblies.aspx#comments</comments><description>&lt;p&gt;Because information about this is actually hard to find (there are loads of samples around about how to demand several rights, but hardly any about locking down your own frameworks&amp;nbsp;&amp;amp; assemblies):&lt;/p&gt; &lt;p&gt;I recommend for most cases to start from no rights at all&amp;nbsp;(except execution and some identity permissions) and then whitelist whatever you need.&lt;/p&gt; &lt;p&gt;&lt;font color="#800000"&gt;[assembly: &lt;strong&gt;PermissionSet&lt;/strong&gt;(SecurityAction.&lt;strong&gt;RequestOptional&lt;/strong&gt;, Name=&amp;quot;&lt;strong&gt;Execution&lt;/strong&gt;&amp;quot;)]&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Note that you have to use RequestOptional, not RequestMinimum (that wouldn&amp;#39;t have any effect! see &lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/09/14/466661.aspx"&gt;here&lt;/a&gt;), because the effective permissions are calculated as follows&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Effective = (RequestMinimum union RequestOptional) - RequestRefuse&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;where by default RequestOptional is FullTrust, Hence you&amp;#39;ll always get FullTrust&amp;nbsp;if you only use RequestMinimum.&lt;/p&gt; &lt;p&gt;Note also that we rely here upon what the user/administrator specified in the &amp;quot;Execution&amp;quot; Permission Set - by default it&amp;#39;s just the SecurityPermission&amp;#39;s Execute Permission and nothing else.&lt;/p&gt; &lt;p&gt;After that just request any additional permissions you may need (&lt;em&gt;RequestOptional&lt;/em&gt;) or you need in any case to make sense (&lt;em&gt;RequestMinimum&lt;/em&gt;), as usual.&amp;nbsp;For example&amp;nbsp;use a FileIOPermission if you need to read some file, or a SocketPermission for network access, with the appropriate SecurityAttribute and parameters:&lt;/p&gt; &lt;p&gt;&lt;font color="#800000"&gt;[assembly: FileIOPermission(SecurityAction.RequestMinimum, ...)]&lt;br /&gt;[assembly: System.Net.SocketPermission(SecurityAction.RequestOptional, ...)]&lt;br /&gt;&lt;/font&gt;...&lt;/p&gt; &lt;p&gt;Earlier I simply used to add &amp;quot;[assembly: SecurityPermission(SecurityAction.RequestRefuse)]&amp;quot; to any of my framework assemblies and thought that&amp;#39;s it, but that was rubbish and didn&amp;#39;t even have any effect. Don&amp;#39;t do it. (Unless I&amp;#39;m very mistaken, please correct me if I am!)&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=55597" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Opensource/default.aspx">Opensource</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/C_2B002B002F00_CLI/default.aspx">C++/CLI</category></item><item><title>C++/CLI: Explicitly Implement Interface Properties</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2007/01/09/ExplicitlyImplementInterfaceProperties.aspx</link><pubDate>Tue, 09 Jan 2007 20:37:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:54905</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;In case you ever wondered how to explicitly implement interface properties in C++/CLI that collide with an already existing better typed property: It&amp;#39;s quite easy, but I didn&amp;#39;t find a sample in neither the language specification&amp;nbsp;nor the web.&lt;/p&gt; &lt;p&gt;Imagine you have some already existing generic&amp;nbsp;ItemBuilder class:&lt;/p&gt; &lt;div style="border:2px ridge white;margin:10px;padding:10px;font-size:10pt;font-family:courier new;background-color:#eeeeee;"&gt;&lt;font color="blue"&gt;ref&amp;nbsp;class&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;Item&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;font color="black"&gt;&lt;font color="blue"&gt;generic&lt;/font&gt;&lt;/font&gt;&amp;lt;&lt;/font&gt;&lt;font color="blue"&gt;class&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;T&amp;gt;&lt;br /&gt;&lt;font color="blue"&gt;where&lt;/font&gt;&amp;nbsp;T&amp;nbsp;:&amp;nbsp;Item&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;public&amp;nbsp;ref&amp;nbsp;class&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;ItemBuilder&lt;br /&gt;{&lt;br /&gt;&lt;font color="blue"&gt;public&lt;/font&gt;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;property&lt;/font&gt;&lt;font color="black"&gt;&amp;nbsp;&lt;/font&gt;T&amp;nbsp;Prototype&amp;nbsp;{&amp;nbsp;T&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;get&lt;/font&gt;&lt;font color="black"&gt;()&lt;/font&gt;&lt;font color="blue"&gt;;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; &lt;/div&gt; &lt;p&gt;But now you want to generalize it, to be able to access the prototype property as Item, independent of the actual generic class type. So you define an interface IItemBuilder:&lt;/p&gt; &lt;div style="border:2px ridge white;margin:10px;padding:10px;font-size:10pt;font-family:courier new;background-color:#eeeeee;"&gt;&lt;font color="blue"&gt;public&amp;nbsp;interface&amp;nbsp;class&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;IItemBuilder&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;property&lt;/font&gt;&lt;font color="black"&gt;&amp;nbsp;&lt;/font&gt;Item^&amp;nbsp;Prototype&amp;nbsp;{&amp;nbsp;Item^&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;get&lt;/font&gt;&lt;font color="black"&gt;()&lt;/font&gt;&lt;font color="blue"&gt;;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;/font&gt; &lt;/div&gt; &lt;p&gt;How to explicitly implement this interface in ItemBuilder in C++/CLI?&lt;/p&gt; &lt;div style="border:2px ridge white;margin:10px;padding:10px;font-size:10pt;font-family:courier new;background-color:#eeeeee;"&gt;&lt;font color="black"&gt;&lt;font color="blue"&gt;generic&lt;/font&gt;&amp;lt;&lt;/font&gt;&lt;font color="blue"&gt;class&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;T&amp;gt;&lt;br /&gt;&lt;font color="blue"&gt;where&lt;/font&gt;&amp;nbsp;T&amp;nbsp;:&amp;nbsp;Item&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;public&amp;nbsp;ref&amp;nbsp;class&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;ItemBuilder&amp;nbsp;:&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;public&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;IPacketBuilder&lt;br /&gt;{&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;private&lt;/font&gt;&lt;font color="black"&gt;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;virtual property&lt;/font&gt;&lt;font color="black"&gt;&amp;nbsp;Item^&amp;nbsp;PrototypeUntyped&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;Item^&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;get&lt;/font&gt;&lt;font color="black"&gt;()&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;sealed&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;IItemBuilder::Prototype::&lt;/font&gt;&lt;font color="blue"&gt;get;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;public&lt;/font&gt;&lt;font color="black"&gt;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="blue"&gt;property&lt;/font&gt;&lt;font color="black"&gt;&amp;nbsp;&lt;/font&gt;T&amp;nbsp;Prototype&amp;nbsp;{&amp;nbsp;T&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;get&lt;/font&gt;&lt;font color="black"&gt;()&lt;/font&gt;&lt;font color="blue"&gt;;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&lt;br /&gt;&lt;/font&gt;&lt;font color="black"&gt;}&lt;/font&gt;&lt;font color="blue"&gt;;&amp;nbsp;&lt;/font&gt; &lt;/div&gt; &lt;p&gt;Let me know if you know a better approach ...&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=54905" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Bits+and+Bytes/default.aspx">Bits and Bytes</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/C_2B002B002F00_CLI/default.aspx">C++/CLI</category></item><item><title>Strange PowerShell Bug?</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2006/09/24/StrangePowerShellBug.aspx</link><pubDate>Sun, 24 Sep 2006 19:19:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:4458</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=4458</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2006/09/24/StrangePowerShellBug.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m fighting with a strange behavior of the MS &lt;strong&gt;PowerShell RC1&lt;/strong&gt;, that might be a &lt;strong&gt;bug&lt;/strong&gt;. It&amp;#39;s about moving and renaming items with &amp;quot;[&amp;quot; or &amp;quot;]&amp;quot; in the name. Strangely they&amp;#39;re simply ignored, sometimes I also get a message that the file does not exist (although I just gathered it using Get-ChildItem!?)&lt;/p&gt; &lt;p&gt;How to reproduce:  &lt;/p&gt;&lt;p&gt;Open PowerShell and create an empty directory:&lt;/p&gt; &lt;p&gt;&amp;gt; mkdir pstest&lt;br /&gt;&amp;gt; cd pstest&lt;/p&gt; &lt;p&gt;Create a file without [ and ] and rename/move it around.&lt;/p&gt; &lt;p&gt;&amp;gt; New-Item abc.txt -type file&lt;br /&gt;&amp;gt; gci *.txt | mi -Destination test.txt // &lt;font color="#008000"&gt;&lt;strong&gt;works&lt;/strong&gt;&lt;/font&gt;&lt;br /&gt;&amp;gt; ri test.txt  &lt;/p&gt;&lt;p&gt;Now try it with a file containing [ and ] in its name. &lt;/p&gt;&lt;p&gt;&amp;gt; New-Item abc.[def].txt -type file&lt;br /&gt;&amp;gt; gci *.txt | mi -Destination test.txt // &lt;font color="#ff0000"&gt;&lt;strong&gt;does NOT work&lt;/strong&gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;In the second case the file is not renamed. Did I misunderstand something? Can you reproduce it? It is an old well known bug?&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=4458" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Bug/default.aspx">Bug</category></item><item><title>Email Address Format Myths</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2006/09/16/Email-Address-Format-Myths.aspx</link><pubDate>Sat, 16 Sep 2006 14:58:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:3531</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=3531</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2006/09/16/Email-Address-Format-Myths.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m used to&amp;nbsp;enter a unique email address&amp;nbsp;whenever I really have to provide one. Up to some weeks ago I used the &amp;quot;reg.{0}@mydomain.com&amp;quot; pattern, where I replaced &amp;quot;{0}&amp;quot; with a name I associate with the site, often the second level domain part (e.g. &amp;quot;amazon&amp;quot;). I applied a set of server side processing rules to&amp;nbsp;move some of them to special folders, and automatically delete mails to blacklisted names. This worked very well for the last, say, 7-8 years. More than once I observed that a name I used to register for a once&amp;nbsp;free service was obviously sold to spammers some months after the service was discontinued, so I just blacklisted this name.&lt;/p&gt; &lt;p&gt;I can do this because I have my own domain and mail server, and I&amp;#39;ve set a catch-all alias. Unfortunately I receive a lot of spam to obviously random generated email aliases (like &amp;quot;abnd798as8fihkasd89@...&amp;quot;), so I finally decided to upgrade my mail server to SmarterMail 3, which not only provides a much better spam filter system, but also allows the so called &lt;strong&gt;plus-addressing&lt;/strong&gt;, allowing the same thing (the format is now &amp;quot;reg+{0}@mydomain.com&amp;quot;, and it automatically moves mails to a {0}-folder (optional: always, only if folder already exists, never)) but without the hassle of&amp;nbsp;a catch-all alias.&lt;/p&gt; &lt;p&gt;At the beginning this worked very well. But soon I got problems because some web apps don&amp;#39;t allow the &amp;quot;+&amp;quot;-character in email addresses. This is strange, since a &amp;quot;+&amp;quot; in the local part (that is the part before the &amp;quot;@&amp;quot;) perfectly legal.&lt;/p&gt; &lt;p&gt;Obviously there exists some strange myths about what characters are allowed in an email address or not. I suspect the reason for some of this myths is that the rules for domain names are very restrictive -&amp;nbsp;domain names indeed don&amp;#39;t allow &amp;quot;+&amp;quot;-characters. But the local-part does, and much more. I&amp;#39;ve also heard myth saying that everything after a &amp;quot;+&amp;quot; is considered as a comment. Or that &amp;quot;+&amp;quot; is considered equal to &amp;quot;@&amp;quot; in case you can&amp;#39;t enter a real&amp;nbsp;&amp;quot;@&amp;quot; for whatever reason. Btw, GMail supports Plus-Addressing (no, they did not invent it!), but the part after the &amp;quot;+&amp;quot; is apparently limited to six characters (I haven&amp;#39;t tested that).&lt;/p&gt; &lt;p&gt;According to &lt;a href="http://tools.ietf.org/html/rfc2821"&gt;RFC2821&lt;/a&gt; (SMTP)&amp;nbsp;and &lt;a href="http://tools.ietf.org/html/rfc2822"&gt;RFC2822&lt;/a&gt; (Internet Message Format), a mailbox address is constructed as follows:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Mailbox = Local-part &amp;quot;@&amp;quot; Domain  &lt;/li&gt;&lt;li&gt;Local-part = Dot-string / Quoted-string  &lt;/li&gt;&lt;li&gt;Dot-string = Atom *(&amp;quot;.&amp;quot; Atom)  &lt;/li&gt;&lt;li&gt;Atom = 1*atext  &lt;/li&gt;&lt;li&gt;atext = ALPHA / DIGIT / &amp;quot;!&amp;quot; / &amp;quot;#&amp;quot; / &amp;quot;$&amp;quot; / &amp;quot;%&amp;quot; / &amp;quot;&amp;amp;&amp;quot; / &amp;quot;&amp;#39;&amp;quot; / &amp;quot;*&amp;quot; / &amp;quot;+&amp;quot; / &amp;quot;-&amp;quot; / &amp;quot;/&amp;quot; / &amp;quot;=&amp;quot; / &amp;quot;?&amp;quot; / &amp;quot;^&amp;quot; / &amp;quot;_&amp;quot; / &amp;quot;`&amp;quot; / &amp;quot;{&amp;quot; / &amp;quot;|&amp;quot; / &amp;quot;}&amp;quot; / &amp;quot;~&amp;quot;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;To summarize, the local part (before @)&amp;nbsp;allows the following characters:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;strong&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;abcdefghijklmnopqrstuvwxyz&lt;br /&gt;0123456789&lt;br /&gt;&lt;font color="#ff0000"&gt;.!#$%&amp;amp;&amp;quot;*+-/=?^_`{|}~&lt;/font&gt;&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;While the domain part (after @) only allows the following characters (except &lt;a href="http://en.wikipedia.org/wiki/Internationalized_domain_name"&gt;IDN&lt;/a&gt;, but that&amp;#39;s another topic):&lt;/p&gt; &lt;ul&gt; &lt;li&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;abcdefghijklmnopqrstuvwxyz&lt;br /&gt;0123456789&lt;br /&gt;.-&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Note that domain names are never case-sensitive, but the local-part might be (allowed, but optional).&lt;/p&gt; &lt;p&gt;Beside of the next best web-app I&amp;#39;ve also heard of some MTAs making problems with local-parts that aren&amp;#39;t valid domain names.&amp;nbsp;Why on earth do developers still validate the whole email address with the domain name rules? Just for simplicity? Please, don&amp;#39;t do that, or I&amp;#39;ll have to put your name to the &amp;quot;&lt;a href="http://mozilla.wikia.com/wiki/User:Me_at_work/plushaters"&gt;plus-haters list of shame&lt;/a&gt;&amp;quot; ;)&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=3531" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Networking/default.aspx">Networking</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Formal+Languages/default.aspx">Formal Languages</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Rant/default.aspx">Rant</category></item><item><title>Agile Hardware Design?</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2006/08/25/Agile-Hardware-Design.aspx</link><pubDate>Fri, 25 Aug 2006 20:43:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:1506</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=1506</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2006/08/25/Agile-Hardware-Design.aspx#comments</comments><description>&lt;p&gt;Looking back at my first semester thesis at &lt;a href="http://www.ethz.ch/"&gt;ETH&lt;/a&gt;, where I &lt;a href="http://dev.cdrnet.net/cs/blogs/computer/archive/2006/05/04/FirstAsic.aspx"&gt;designed a full-custom ASIC&lt;/a&gt;, I realize something odd:&lt;/p&gt; &lt;p&gt;In VLSI design, especially when designing ASICs or ASIPs (not so much on FPGAs), people make a real fuss about &lt;strong&gt;testing&lt;/strong&gt;. For a good reason, since &lt;font color="#0080ff"&gt;A)&lt;/font&gt; the fabrication setup is expensive and really slow (you speak in&amp;nbsp;terms of months), and even more important, since &lt;font color="#0080ff"&gt;B)&lt;/font&gt; the fabrication is error-prone. As a side note,&amp;nbsp;in practice it is not economic to fabricate error-free, as such a process&amp;nbsp;would be&amp;nbsp;clearly far from the density limit. Hence you usually accept a yield of, say, Y=95%. Having a fault coverage T leads to a defect level of DF = 1-Y^(1-T). To minimize this you want a high fault coverage (e.g. T &amp;gt; 99.9%).&lt;/p&gt; &lt;p&gt;Part &lt;font color="#0080ff"&gt;A)&lt;/font&gt; is about &lt;strong&gt;functional tests&lt;/strong&gt; to ensure the IC does what you intend, while &lt;font color="#0080ff"&gt;B)&lt;/font&gt; is about testing whether the chip fabric actually produced error-free what you told them to - you examine every single IC with this test, often directly on the waver.&lt;/p&gt; &lt;p&gt;Interestingly there is a very nice tool support for &lt;font color="#0080ff"&gt;B)&lt;/font&gt;. A common practice are &lt;strong&gt;&lt;a href="http://en.wikipedia.org/wiki/Scan_chain"&gt;scan chains&lt;/a&gt;&lt;/strong&gt;,&amp;nbsp;a simple technique&amp;nbsp;where you&amp;nbsp;insert additional logic to systematically set the values of every single register on the chip with only few additional I/O pads&amp;nbsp;(actually,&amp;nbsp;a tool inserts this automatically). Using such chains and a&amp;nbsp;given fault model, another tool then &lt;a href="http://en.wikipedia.org/wiki/ATPG"&gt;automatically generates a huge set of test vectors&lt;/a&gt;, trying to reach 100% fault coverage with as few vectors as possible.&lt;/p&gt; &lt;p&gt;Now the odd part, when we come to &lt;font color="#0080ff"&gt;A)&lt;/font&gt;: No one seems to apply &lt;strong&gt;Unit Testing&lt;/strong&gt;, or has ever heard of anything like &amp;quot;agile&amp;quot; methodologies. Ok, they do functional testing, but only the on whole chip (and to be fair, also on IP blocks - usually this means generating an input vector sequence and compare the simulated outputs with the expectations); and it probably depends on the environment. But I think there doesn&amp;#39;t even exist a tool like NUnit/JUnit for VHDL, let alone a continuous integration server (although you could theoretically write&amp;nbsp;some NAnt task adapters and use a common CI server). Looks like there&amp;#39;s not that much communication between the hardware and the software world, or at least not on methodological aspects?&lt;/p&gt;&lt;p&gt;Btw, there is a ruby based hardware description language called &lt;a href="http://www.aracnet.com/~ptkwt/ruby_stuff/RHDL/"&gt;RHDL&lt;/a&gt;, trying to unify object oriented and agile concepts with VHDL. Might be interesting!&lt;br /&gt;&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=1506" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/ASIC/default.aspx">ASIC</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Thesis/default.aspx">Thesis</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Hardware/default.aspx">Hardware</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Agile/default.aspx">Agile</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/VHDL/default.aspx">VHDL</category></item><item><title>Kakuro Combinations</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2006/08/23/Kakuro-Combinations.aspx</link><pubDate>Wed, 23 Aug 2006 19:26:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:1267</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=1267</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2006/08/23/Kakuro-Combinations.aspx#comments</comments><description>&lt;p&gt;Enough&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Sudoku"&gt;Sudoku&lt;/a&gt;&amp;nbsp;for a while? Try &lt;a href="http://en.wikipedia.org/wiki/Kakuro"&gt;Kakuro&lt;/a&gt;!&lt;/p&gt;
 
&lt;p&gt;I&amp;#39;ve created a small helper table lately, listing what numbers are possible in what condition (dependent on the required sum and the number of fields). You may download it as a PDF (see attachment):&lt;br /&gt;
&lt;/p&gt;

&lt;p&gt;&lt;img height="227" src="http://dev.cdrnet.net/webfiles/4e0fdbe71745_F562/Kakuro12.png" width="418" /&gt; &lt;/p&gt;
 
&lt;p&gt;I could have evaluated the allowed numbers by hand, but decided to write a small console code snippet in C# instead. It&amp;#39;s neither optimized nor well designed, but it works... *note to myself: use a functional language next time*&lt;/p&gt;
 
&lt;p&gt;Call the method Kakuro(s,f) with the required sum in &lt;strong&gt;s&lt;/strong&gt; and the number of fields in &lt;strong&gt;f&lt;/strong&gt;, and it returns all possible combinations (only&amp;nbsp;the ascending&amp;nbsp;permutation for each)&amp;nbsp;and the union set of numbers appearing in at least one combination (that&amp;#39;s the numbers in the helper table above)&lt;/p&gt;
 
&lt;p&gt;The recursive backtracking method (with inline console output for simplicity):&lt;/p&gt;

&lt;pre&gt;static BitArray AppendSummand(int summandsLeft, int targetSum, BitArray used, int sum, int nextSummand)&lt;br /&gt;{
&amp;nbsp;&amp;nbsp; if(summandsLeft == 0)
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(targetSum == sum)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp;// found valid solution
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PrintUsed(used, false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return used;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else // invalid solution A
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new BitArray(9);
&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; if(nextSummand &amp;gt;= 10) // invalid solution B
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return new BitArray(9);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; BitArray usedWith = new BitArray(used);
&amp;nbsp;&amp;nbsp; usedWith[nextSummand-1] = true; // try with this number
&amp;nbsp;&amp;nbsp; BitArray resultWithout = AppendSummand(summandsLeft, targetSum, used, sum, nextSummand+1);
&amp;nbsp;&amp;nbsp; BitArray resultWith = AppendSummand(summandsLeft-1, targetSum, usedWith, sum+nextSummand, nextSummand+1);
&amp;nbsp;&amp;nbsp; // combine results for the summary
&amp;nbsp;&amp;nbsp; return resultWithout.Or(resultWith);
}&lt;/pre&gt;

&lt;p&gt;And the method to run it:&lt;/p&gt;

&lt;pre&gt;static void Kakuro(int sum, int fields)
{
&amp;nbsp;&amp;nbsp; Console.WriteLine(&amp;quot;==================================&amp;quot;);
&amp;nbsp;&amp;nbsp; Console.WriteLine(&amp;quot;** Sum {0} in {1} cells&amp;quot;,sum,fields);
&amp;nbsp;&amp;nbsp; BitArray used = new BitArray(9);
&amp;nbsp;&amp;nbsp; BitArray res = AppendSummand(fields,sum,used,0,1);
&amp;nbsp;&amp;nbsp; Console.Write(&amp;quot;** Superset: &amp;quot;);
&amp;nbsp;&amp;nbsp; PrintUsed(res, true);
&amp;nbsp;&amp;nbsp; Console.WriteLine();
}&lt;br /&gt;
&lt;/pre&gt;

&lt;p&gt;Finally the print method used to print the numbers to the console:&lt;/p&gt;

&lt;pre&gt;static void PrintUsed(BitArray used, bool all)
{
&amp;nbsp;&amp;nbsp; Console.ForegroundColor = ConsoleColor.Green;
&amp;nbsp;&amp;nbsp; if(all)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0;i&amp;lt;used.Length;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.ForegroundColor = used[ i ] ? ConsoleColor.Green : ConsoleColor.Red;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Write((i+1).ToString() + &amp;quot; &amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0;i&amp;lt;used.Length;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(used[ i ])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Write((i+1).ToString() + &amp;quot; &amp;quot;);
&amp;nbsp;&amp;nbsp; Console.ResetColor();
&amp;nbsp;&amp;nbsp; Console.WriteLine();
}&lt;br /&gt;
&lt;/pre&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=1267" width="1" height="1"&gt;</description><enclosure url="http://community.opensourcedotnet.info/blogs/computer/attachment/1267.ashx" length="39067" type="application/pdf" /><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Games/default.aspx">Games</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Algorithms/default.aspx">Algorithms</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category></item><item><title>My first ASIC</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2006/05/04/FirstAsic.aspx</link><pubDate>Thu, 04 May 2006 16:05:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:292</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=292</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2006/05/04/FirstAsic.aspx#comments</comments><description>The last term I designed my first ASIC with a colleague, as part of a semester thesis. It realizes a new algorithm and datastructure for on-chip IP address lookup for classless interdomain routing. The algorithm only needs about 6 memory access to per lookup, in order find the right of about 1500 ranges, stored in 4.5 KB on-chip SRAM.&lt;br&gt;&lt;br&gt;We were constrained to a chip size of 5.93 mm^2 and a core size of only 3.56 mm^2 (1.887 mm side length). It was manufactured in a 0.250 um process and runs at 166 MHz, processing about 10-15 million lookups per second.&lt;br&gt;&lt;br&gt;Our final backend design:&lt;br&gt;&lt;br&gt;&lt;a href="http://dev.cdrnet.net/cs/photos/various/AsicLayout.aspx" target="_blank"&gt;&lt;img src="http://dev.cdrnet.net/cs/photos/various/images/original/AsicLayout.aspx" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;The "lookup table" is stored in the two SRAM microcells in the top left corner. The additional cell in the right is needed for the tree construction algorithm for building the table internally.&lt;br&gt;&lt;br&gt;I tried to scan the chip on my flatbed scanner, but of course without much luck. ;)&lt;br&gt;Remember, the chip has a side length of only 2.5 mm. Here is the result:&lt;br&gt;&lt;br&gt;&lt;a href="http://dev.cdrnet.net/cs/photos/various/AsicFlatbed.aspx" target="_blank"&gt;&lt;img src="http://dev.cdrnet.net/cs/photos/various/images/original/AsicFlatbed.aspx" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;Luckily the microscope helps out. Here a better shot. Unfortunately you don't really see much of it, because the design center guys decided it would be better to fill the topmost metal 5 layer completely:&lt;br&gt;&lt;br&gt;&lt;a href="http://dev.cdrnet.net/cs/photos/various/AsicPoster.aspx" target="_blank"&gt;&lt;img src="http://dev.cdrnet.net/cs/photos/various/images/original/AsicPoster.aspx" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;Nevertheless, it was a very interesting project. Let me know if you need a chip designer ;).&lt;br&gt;&lt;br&gt;Next step is testing ...&lt;br&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=292" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/ASIC/default.aspx">ASIC</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Thesis/default.aspx">Thesis</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Hardware/default.aspx">Hardware</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Networking/default.aspx">Networking</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/ETH/default.aspx">ETH</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Routing/default.aspx">Routing</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Bits+and+Bytes/default.aspx">Bits and Bytes</category></item><item><title>English Blog from now on</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2006/04/23/EnglishNow.aspx</link><pubDate>Sun, 23 Apr 2006 00:41:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:157</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=157</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2006/04/23/EnglishNow.aspx#comments</comments><description>This blog used to be german, but I'll write in english from now on.
Drop me a line if you think my english is too bad and I'd better switch
back to german immediately ... ;)&lt;br&gt;&lt;br&gt;Beside of the language, I'll also shift the topic slightly. I'll write about computers and software in general, but also about other topics from &lt;a href="http://www.ethz.ch"&gt;"college" (ETHz)&lt;/a&gt;, thesis and the like.&lt;br&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=157" width="1" height="1"&gt;</description></item><item><title>Equidistant Letter Sequences und Regular Expressions</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2004/12/30/EquidistandLetterSequencesRegex.aspx</link><pubDate>Thu, 30 Dec 2004 01:56:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:118</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=118</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2004/12/30/EquidistandLetterSequencesRegex.aspx#comments</comments><description>&lt;p&gt;Heute hat mich per WebForm Jemand gefragt ob Wörter aus äquidistante
Buchstabensequenzen (ELS) mit regulären Ausdrücken erkannt werden
können. Beispielsweise soll geprüft werden, ob das Wort &lt;i&gt;"foo"&lt;/i&gt; als ELS im Text &lt;i&gt;"abf1 2o 3bor z32"&lt;/i&gt; vorkommt (tut es, mit Intervalllänge 4 (f suchen, dann jeweils 3 Zeichen überspringen)).&lt;/p&gt;

&lt;p&gt;Eine äquidistande Buchstabensequenz mit unbekannter und beliebig grosser Intervalllänge n ist &lt;b&gt;keine reguläre Sprache und kann folglich nicht mit einem regulären Ausdruck beschrieben werden&lt;/b&gt;. Dies kann einfach mit dem Pumping Lemma bewiesen werden.&lt;/p&gt;

&lt;p&gt;Falls allerdings das gesuchte Wort bekannt und die Intervalllänge
mit einem Maxima m eingegrenz werden kann (n&amp;lt;=m) ist die Sprache
regulär und kann mit einem regulären Ausdruck beschrieben werden - wenn
auch mit einem hässlichen:
"(f.{0}o.{0}o|f.{1}o.{1}o|f.{2}o.{2}o|...|f.{m}o.{m}o)" (Das Pattern
muss m mal wiederholt werden, mit jeweils inkrementierter Zahl zwischen
den geschweiften Klammern).&lt;/p&gt;

&lt;p&gt;Falls ELS im grösseren Rahmen erkannt werden sollten, lohnt es sich
wohl einen kleinen eigenen Parser zu schreiben statt die Regex zu
verwenden - mit einem solchen einfachen spezialisierten Parser ergibt
sich die Intervalllängenbeschränkung, und das ganze wird wahrscheinlich
wesentlich performanter ablaufen...&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=118" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Regex/default.aspx">Regex</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Formal+Languages/default.aspx">Formal Languages</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Algorithms/default.aspx">Algorithms</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category></item><item><title>A C# Framework for Interprocess Synchronization and Communication</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2004/09/30/ThreadMessagingFramework.aspx</link><pubDate>Thu, 30 Sep 2004 20:23:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:124</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=124</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2004/09/30/ThreadMessagingFramework.aspx#comments</comments><description>&lt;p&gt;Mit &lt;a href="http://www.cdrnet.ch/projects/threadmsg/"&gt;ThreadMessaging.NET&lt;/a&gt;
habe ich diesen Herbst eine weitere kleine Bibliothek in C# geschrieben
(opensource, BSD Lizenz), ein Framework für fortgeschrittene
transparente Synchronisation und Kommunikation zwischen verschiedenen
Threads und Prozessen (auch über Rechnergrenzen hinweg) in der .NET
Welt, die sichere Implementationen verschiedener
Nachrichtenübermittlungs- und Datenflusssteuerungsstrukturen
bereitstellt.&lt;/p&gt;

&lt;p&gt;Begleitend dazu habe ich einen &lt;a href="http://www.codeproject.com/csharp/csthreadmsg.asp"&gt;Artikel bei CodeProject&lt;/a&gt; verfasst, der nun offenbar sogar die monthly competition (august 04) gewann. Vielen Dank für die interessanten Preise :)&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=124" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Networking/default.aspx">Networking</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Opensource/default.aspx">Opensource</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Codeproject/default.aspx">Codeproject</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/IPC/default.aspx">IPC</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category></item><item><title>Bitwise: Bin&amp;amp;amp;#228;re Spielchen</title><link>http://community.opensourcedotnet.info/blogs/computer/archive/2003/10/04/BinaryTricks.aspx</link><pubDate>Fri, 03 Oct 2003 22:09:00 GMT</pubDate><guid isPermaLink="false">5e0c48d9-3477-4155-b28a-6cca64e53d2a:125</guid><dc:creator>Christoph Rüegg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://community.opensourcedotnet.info/blogs/computer/rsscomments.aspx?PostID=125</wfw:commentRss><comments>http://community.opensourcedotnet.info/blogs/computer/archive/2003/10/04/BinaryTricks.aspx#comments</comments><description>&lt;p&gt;Ich bin hin und wieder erstaunt, wie unbekannt die bitwise
Operatoren bei vielen&amp;nbsp;Programmierern doch sind. Gehört hat man davon,
vielleicht schon mal&amp;nbsp;einige Beispiele gesehen, doch so richtig
verstanden hat man sie doch nicht, selber angewendet sowieso nicht.
Desshalb habe ich mich entschieden, diesen kleinen Artikel zu schreiben
und hier zu publizieren...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Einführung&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Bei modernen Sprachen wie C# merkt man nicht mehr viel von der
Hardware, auf dem die Anwendungen schlussendlich ablaufen soll.
Konzepte wie das der Objektorientierung abstrahieren von der
Architektur des Mikroprozessors besonders stark. Trotzdem stehen
auch&amp;nbsp;in C#&amp;nbsp;nützliche Werkzeuge aus der Digitaltechnik zur Verfügung:
Bitwise Operatoren. Diese Operatoren sind in &lt;a href="http://www.cdrnet.net/projects/cmos/"&gt;CMOS&lt;/a&gt;
sehr einfach zu implementieren und haben eine konstante Laufzeit da
vollständig parallelisierbar. Dafür sind sie umso mächtiger,&amp;nbsp;ist doch
ein Mikroprozessor ansich auch nicht viel mehr&amp;nbsp;als eine
sinnvolle&amp;nbsp;Verschaltung einzelner CMOS Gatter wie NANDs (negiertes Und),
NORs (negiertes Oder), XORs (negierte Gleichheit)&amp;nbsp;oder NOTs
(Inversion). Wendet man diese Gatter parallel auf jedes Bit eines
ganzen Buses an (der zb, falls 32 Bit breit, gerade eine C#
Integer-Zahl repräsentiert), so erhält man die erwähnten bitwise
Operatoren. (Einfachheitshalber arbeite ich&amp;nbsp;in diesem Artikel&amp;nbsp;nur mit&amp;nbsp;8
Bits = 1 Byte).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Binärzahlen&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Um bitwise Operatoren zu verstehen ist es unumgänglich, zu Verstehen wie eine Ganzzahl (Integer) als Binärzahl dargestellt wird.&lt;/p&gt;
&lt;p&gt;Ein Bit ("eine Datenleitung") kann genau 2 Zustände annehmen: 1 und
0 (vgl. Boolean: 1=true, 2=false). Gruppiert man nun 8 Bits zusammen,
so erhält man einen 8 Bit breiten Bus, der 2^8 = 256 verschiedene
Zustände, und somit 256 Zahlen&amp;nbsp;darstellen kann. Damit diese Zustände
eindeutig Zahlen zugeordnet werden können hat sich eine Konvention
(=Code)&amp;nbsp;bewährt, die am einfachsten mit ein par Beispielen gezeigt
werden kann:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;00000000 = 0&lt;br&gt;00000001 = 1&lt;br&gt;00000010 = 2&lt;br&gt;00000011 = 3&lt;br&gt;00000100 = 4&lt;br&gt;00000101 = 5&lt;br&gt;...&lt;br&gt;11111111 = 255&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Dabei stellt jede Ziffer ein Bit dar; die Ziffer ganz links heist
MSB (Most Significant Bit), die ganz rechts LSB (Least Significant Bit).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Das 2er Komplement&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ein C# Integer&amp;nbsp;kann auch negative Zahlen darstellen. Dazu verwendet
man das Bit ganz links für das Vorzeichen. Dadurch stehen dann
allerdings pro Vorzeichen&amp;nbsp;nur noch 2^7 = 128 verschiedene Zustände zur
Verfügung. Mit 8 bits kann man daher, alternativ zum oben vorgestellten
(unsigned) Code mit dem Bereich 0..255, auch den (signed) Bereich
-128..127 darstellen (0 zählt als positive Zahl, daher ist die grösste
positive Zahl 127, nicht 128!). Dazu wieder einige Beispiele:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;10000000 = -128&lt;br&gt;10000001 = -127&lt;br&gt;...&lt;br&gt;11111110 = -2&lt;br&gt;11111111 = -1&lt;br&gt;00000000 = 0&lt;br&gt;00000001 = 1&lt;br&gt;...&lt;br&gt;01111110 = 126&lt;br&gt;01111111 = 127&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Die positiven Zahlen funktionieren also abgesehen vom ersten Bit
genau wie zuvor. Bemerkenswert ist hier vielleicht, dass (-1)&amp;nbsp;+ 1 0
ergiebt, 127 plus 1 jedoch (-128)! Doch wie negiert man eine Zahl, zB.
'5'? Dazu braucht man erst die Zahl in Binärform. Dann dreht man jedes
Bit um (1-&amp;gt;0, 0-&amp;gt;1) und addiert eine 1:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;00000101 = 5&lt;br&gt;11111010 = -6&lt;br&gt;11111011 = -5&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;00000100 = 4&lt;br&gt;11111011 = -5&lt;br&gt;11111100 = -4&amp;nbsp; &lt;/font&gt;&lt;font face="Arial"&gt;(beachte hier den Übertrag: 10 + 01 = 11, 101 + 001 = 110, 011 + 001 = 100, 11 + 01 = 00)&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;00000000 = 0&lt;br&gt;11111111 = -1&lt;br&gt;00000000 = 0&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Das letzte Beispiel zeigt einen klassischen Überlauf: 011 + 001 =
100. Das führende 1 wird hier jedoch abgeschnitten, da ja kein Platz
für eine weitere Stelle vorhanden ist!&lt;/p&gt;
&lt;p&gt;Das praktische am 2er Kompelement ist u.a., dass auch die Addition
von negativen und gemischten Zahlen genau gleich funktioniert wie
bisher, und die Subtraktion sehr einfach auf die Addition mit einem
negierten Summanden zurückgeführt werden kann. So lassen sich mit
einem&amp;nbsp;simplen&amp;nbsp;&lt;a href="http://www.cdrnet.ch/projects/cmos/padd4bit.asp"&gt;Ripple-Carry-Addierer&lt;/a&gt; sehr einfach &lt;a href="http://www.cdrnet.ch/projects/cmos/paddsub4bit.asp"&gt;Addier-Subtrahier-Werke&lt;/a&gt; mit bereits sehr interessanten Funktionen konstruieren. Damit hat man dann schon fast eine einfache &lt;a href="http://www.cdrnet.ch/projects/cmos/alu4bit.asp"&gt;ALU (Arithmetisch Logische Einheit, der Kern jedes Mikroprozessors&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Bitwise Operatoren&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In C# stehen folgende bitwise Operatoren zur Verfügung:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;AND/und (a&amp;amp;b):&amp;nbsp;für jedes Bit:&amp;nbsp;1 wenn a und b&amp;nbsp;beide&amp;nbsp;1 sind. 
&lt;/li&gt;&lt;li&gt;OR/oder (a|b): für jedes Bit: 1, wenn a oder b oder beide&amp;nbsp;1 sind. 
&lt;/li&gt;&lt;li&gt;XOR/exklusives oder&amp;nbsp;(a^b): für jedes Bit:&amp;nbsp;1, wenn a oder b (aber nicht beide gleichzeitig!)&amp;nbsp;1 ist. 
&lt;/li&gt;&lt;li&gt;INV/komplement (~a): für jedes Bit: 1 wenn a 0 ist, 0 wenn a 1 ist
&lt;/li&gt;&lt;li&gt;SHIFT (a&amp;lt;&amp;lt;n,a&amp;gt;&amp;gt;n): Verschiebt alle Bits um n Stellen&amp;nbsp;nach links bzw. rechts und füll mit 0 auf.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Bitwise Operatoren sind besonders interessant, wenn man in den einzelnen Bits&amp;nbsp;gezielt Informationen hinterlegen will.&lt;/p&gt;
&lt;p&gt;Was haben die einzelnen Operatoren nun für Auswirkungen auf den Bus
als ganzes, bzw. für was kann man sie in der Praxis gebrauchen?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Der UND Operator '&amp;amp;'&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Dieser Operator ist besonders praktisch um einen Bus mit einer Maske
zu filtern. Wenn uns zb. nur das 2., 3. und 5. Bit (von rechts)
interessiert können wir ihn mit der Maske '00010110' filtern. Alle
anderen Bits werden dabei auf 0 gesetzt:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;01010101 &amp;amp; 00010110 = 00010100&lt;br&gt;10101010 &amp;amp; 00010110 = 00000010&lt;br&gt;00010110 &amp;amp; 00010110 = 00010110&lt;br&gt;11101001 &amp;amp; 00010110 = 00000000&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;So kann man z.B. prüfen ob in a=7 das 3. bit gesetzt ist (was hier atsächlich der Fall ist):&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;int a = 7;&amp;nbsp;//7 = 00000111&lt;br&gt;if((a&amp;nbsp;&amp;amp; 4) == 4) {//4 = 00000100&amp;nbsp;Achtung: der linke Teil mus geklammert werden!&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //...&lt;br&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Der OR Operator '|'&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Mit OR kann man beispielsweise ein Bit oder eine ganze Folge von Bits auf 1 setzen.&lt;/p&gt;
&lt;p&gt;Sollen beispielsweise in a=12 das 2. und&amp;nbsp;3. Bit auf 1 gesetzt werden, so geht das mit folgendem Code:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;int a = 12; //12 = 00001100&lt;br&gt;a = a|6; //6 = 00000110&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;a hat danach den Wert 14 = 00001110&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Der XOR Operator '^'&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Damit kann man ein einzelnes Bit oder eine ganze Folge von Bits invertieren.&lt;/p&gt;
&lt;p&gt;Sollen beispielsweise das 2. und 3. Bit invertiert werden, so geht das wie folgt:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;int b = 6; //6 = 00000110&lt;br&gt;12^b =&amp;nbsp;10 //12 = 00001100,&amp;nbsp;10 = 00001010&lt;br&gt;14^b = 8 //14 = 00001110, 8 = 00001000&lt;br&gt;0^b = 6&lt;br&gt;b^b = 0&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Der Komplement Operator '~'&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;.. ist beispielsweise hilfreich, um ein Bit oder eine Folge von Bits auf 0 zu setzen:&lt;/p&gt;
&lt;p&gt;Sollen beispielsweise bei a=12 das 2. und 3. Bit&amp;nbsp;auf 0 gesetzt&amp;nbsp;werden, so geht das wie folgt:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;int b = 6; //6 = 00000110 -&amp;gt; ~6 = 11111001&lt;br&gt;12&amp;amp;(~b) =&amp;nbsp;8 //12 = 00001100,&amp;nbsp;8 = 00001000&lt;br&gt;14&amp;amp;(~b) = 8 //14 = 00001110&lt;br&gt;0&amp;amp;(~b) = 0&lt;br&gt;b&amp;amp;(~b) = 0&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;Was passiert dabei genau? ~b dreht
jedes Bit von b um. Somit haben wir genau die inverse Maske. Wir
filtern die Eingabe also mit dieser inversen Maske, womit alle Bits,
die in b 1 waren, nun im Ergebnis 0 sind.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;Hinweis: ~6 = -7. Siehe oben "2er Komplement". -6 ist somit ~6+1!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Die SHIFT Operatoren '&amp;lt;&amp;lt;' und '&amp;gt;&amp;gt;'&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Das Shiften ist die schnellste Methode, um eine Zahl n mal&amp;nbsp;mit 2 zu multiplizieren bzw. zu dividieren.:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;1&amp;lt;&amp;lt;1 = 2 //00000010&lt;br&gt;1&amp;lt;&amp;lt;2 = 4 //00000100&lt;br&gt;3&amp;lt;&amp;lt;2 =&amp;nbsp;12 //000001100&lt;br&gt;12&amp;gt;&amp;gt;2 = 3 //00000011&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Die Shift Operatoren sind daher auch praktisch um all die oben
verwendeten Masken zu generieren. Eine Maske&amp;nbsp;für das 2. und 5. Bit kann
beispielsweise wie folgt generiert werden:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;(1&amp;lt;&amp;lt;1)|(1&amp;lt;&amp;lt;4) &lt;font face="Arial"&gt;äquivalent mit&lt;/font&gt; (00000010)|(00010000) &lt;font face="Arial"&gt;äquivalent mit 00010010, der gesuchten Maske.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Eine klassische Anwendung solcher Masken ist das Subnetting im IP Netzwerkprotokoll ("Subnetmask")&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Eine praktische Anwendung der genannten Operatoren: Flags&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Enumerationen sind eine praktische Sache. Manchmal wäre es
aber&amp;nbsp;besonders praktisch, wenn man auch mehrere Einträge der
Enumeration gleichzeitig gewählt werden können. Dazu "dekoriert" man
die Enumeration mit dem [Flags] Attribut und weist den Elementen
Potenzen von 2 zu (0,1,2,4,8,..,256,..):&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;[Flags]&lt;br&gt;public enum AssemblyNameFlags: int&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; None = 0,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PublicKey = 1,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Retargetable = 256&lt;br&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Nun kann man man auch durch den OR Operator gemischte Werte zuweisen (a hat danach den Wert 257):&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;AssemblyNameFlags a = AssemblyNameFlags.PublicKey | AssemblyNameFlags.Retargetable;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Abfragen, ob PublicKey definiert ist:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;if((a &amp;amp; AssemblyNameFlags.PublicKey) == AssemblyNameFlags.PublicKey) { code..; }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Das PublicKey Flag nachträglich setzen (falls bereits definiert ändert sich nichts):&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;a |= AssemblyNameFlags.PublicKey;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Das PublicKey Flag nachträglich entfernen (falls es nicht gesetzt ist ändert sich nichts):&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;a &amp;amp;= ~AssemblyNameFlags.PublicKey;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Zum Schluss noch ein kleines Code Beispiel&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" size="2"&gt;[Flags]&lt;br&gt;public enum MySuperFlag: int&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; blue = 1,&lt;br&gt;&amp;nbsp;&amp;nbsp; round = 2,&lt;br&gt;&amp;nbsp;&amp;nbsp; warm = 4,&lt;br&gt;&amp;nbsp;&amp;nbsp; blueAndWarm = 5 // = blue | warm&lt;br&gt;&amp;nbsp;&amp;nbsp; ... = 8&lt;br&gt;&amp;nbsp;&amp;nbsp; ... = ...&lt;br&gt;}&lt;br&gt;&lt;br&gt;MySuperFlag msf = MySuperFlag.blue;&lt;br&gt;public MySuperFlag SuperFlag //direkter Zugriff auf die Enumeration&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; set {msf = value;}&lt;br&gt;&amp;nbsp;&amp;nbsp; get {return msf;}&lt;br&gt;}&lt;br&gt;public bool IsRoundObject //direkter Zugriff auf ein einzelnes Flag der Enumeration&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; get {return (msf &amp;amp; MySuperFlag.round) == MySuperFlag.round;}&lt;br&gt;&amp;nbsp;&amp;nbsp; set&lt;br&gt;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(value)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msf |= MySuperFlag.round;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msf &amp;amp;= ~MySuperFlag.round;&lt;br&gt;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}&lt;/font&gt;&lt;/p&gt;&lt;img src="http://community.opensourcedotnet.info/aggbug.aspx?PostID=125" width="1" height="1"&gt;</description><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Bits+and+Bytes/default.aspx">Bits and Bytes</category><category domain="http://community.opensourcedotnet.info/blogs/computer/archive/tags/Software/default.aspx">Software</category></item></channel></rss>