<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Fiddler&#039;s Blog</title>
	<atom:link href="http://fiddlerboy.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fiddlerboy.wordpress.com</link>
	<description>Stuff that your teacher didn&#039;t tell you in class</description>
	<lastBuildDate>Tue, 30 Aug 2011 22:00:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fiddlerboy.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Fiddler&#039;s Blog</title>
		<link>http://fiddlerboy.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fiddlerboy.wordpress.com/osd.xml" title="Fiddler&#039;s Blog" />
	<atom:link rel='hub' href='http://fiddlerboy.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Abusing C++ exceptions</title>
		<link>http://fiddlerboy.wordpress.com/2010/01/16/abusing-c-exceptions/</link>
		<comments>http://fiddlerboy.wordpress.com/2010/01/16/abusing-c-exceptions/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 09:54:48 +0000</pubDate>
		<dc:creator>Fiddler</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[exception]]></category>

		<guid isPermaLink="false">http://fiddlerboy.wordpress.com/?p=115</guid>
		<description><![CDATA[Java and C# programmers use exceptions all over the place in their programs. C++ programmers have always been rather shy when it comes to exceptions. I&#8217;m not a particularly big fan of exceptions, but I find them helpful in getting me out of recursion trees! The following snippet shows a typical recursive function that aims [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fiddlerboy.wordpress.com&amp;blog=3660322&amp;post=115&amp;subd=fiddlerboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Java and C# programmers use exceptions all over the place in their programs. C++ programmers have always been rather shy when it comes to exceptions. I&#8217;m not a particularly big fan of exceptions, but I find them helpful in getting me out of recursion trees!</p>
<p>The following snippet shows a typical recursive function that aims to find a target value by brute force. I&#8217;ve left out the details in order to highlight the most important feature : breaking out of the recursion tree once the value is found.</p>
<pre class="brush: cpp;">
void go(int i)
{
   if(i == n)
   {
      // Perform calculation

      if (resultFound)
      {
         // This breaks out of the entire recursion
         // tree and goes back to main!
         throw 1;
      }
   }
   else
   {
      state[i] = value1;
      go(i+1);
      state[i] = value2;
      go(i+1);
   }
}

int main()
{
   try {
      go(0);
   } catch(...) {}

   return 0;
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fiddlerboy.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fiddlerboy.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fiddlerboy.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fiddlerboy.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fiddlerboy.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fiddlerboy.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fiddlerboy.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fiddlerboy.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fiddlerboy.wordpress.com&amp;blog=3660322&amp;post=115&amp;subd=fiddlerboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fiddlerboy.wordpress.com/2010/01/16/abusing-c-exceptions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/732364b215a9a8c161e68d2015a78b57?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">Fiddler</media:title>
		</media:content>
	</item>
		<item>
		<title>The magic of bitmasks</title>
		<link>http://fiddlerboy.wordpress.com/2010/01/15/the-magic-of-bitmasks/</link>
		<comments>http://fiddlerboy.wordpress.com/2010/01/15/the-magic-of-bitmasks/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 02:20:54 +0000</pubDate>
		<dc:creator>Fiddler</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[bitmask]]></category>

		<guid isPermaLink="false">http://fiddlerboy.wordpress.com/?p=83</guid>
		<description><![CDATA[Consider the simple problem of iterating over all the subsets of a given set. For years I&#8217;ve been using recursion to do this, until I came across this neat trick. The magic is contained in the fact that every integer has a binary form, and we can use the individual bits to represent elements in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fiddlerboy.wordpress.com&amp;blog=3660322&amp;post=83&amp;subd=fiddlerboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Consider the simple problem of iterating over all the subsets of a given set. For years I&#8217;ve been using recursion to do this, until I came across this neat trick. The magic is contained in the fact that every integer has a binary form, and we can use the individual bits to represent elements in a set. Confused? Have a look at these numbers :</p>
<p>0, 1, 2, 3, 4, 5, 6, 7</p>
<p>Still doesn&#8217;t make sense? Let&#8217;s write them out in binary :</p>
<p>000, 001, 010, 011, 100, 101, 110, 111</p>
<p>See something now? Aha! If we use the position of the 1s to correspond to a particular element in a 3-element subset, we have just generated all of it&#8217;s subsets by just running through a list of increasing numbers! Well, not quite. There is still the simple matter of using the information in these binary numbers to do the actual listing.</p>
<p>We can check if a particular bit is set by using the bitwise-AND operator. By looking at which bits are set and displaying the element only if it&#8217;s corresponding bit is set, we can write a simple subset listing program :</p>
<pre class="brush: cpp;">
#include &lt;iostream&gt;
using namespace std;

int main()
{
   char arr[] = &quot;abc&quot;;

   for(int i=0 ; i&lt;8 ; i++)
   {
      for(int j=0 ; j&lt;3 ; j++)
         if(i &amp; (1&lt;&lt;j))
            cout &lt;&lt; arr[j];
      cout &lt;&lt; endl;
   }

   return 0;
}
</pre>
<p>This is a small example that works on a set of 3 elements. How about larger sets? No problem! However, you are bounded by the size of the integer that you use. So if you use a 32-bit integer, you cannot use this trick on sets with more than 31 elements.</p>
<p>Also, keep in mind that a set with N elements has 2^N subsets (including the null subset). </p>
<p>Let&#8217;s put this idea into a program that works on strings of variable length :</p>
<pre class="brush: cpp;">
#include &lt;iostream&gt;
#include &lt;cstring&gt;
using namespace std;

int main()
{
   char arr[50];

   cout &lt;&lt; &quot;Enter string : &quot;;
   cin &gt;&gt; arr;

   int len = strlen(arr);

   if(len &gt;= 8 * sizeof(int))
   {
      cout &lt;&lt; &quot;String too long!\n&quot;;
      return 1;
   }

   for(int i=0 ; i &lt; (1&lt;&lt;len) ; i++)
   {
      for(int j=0 ; j &lt; len ; j++)
         if(i &amp; (1&lt;&lt;j))
            cout &lt;&lt; arr[j];
      cout &lt;&lt; endl;
   }

   return 0;
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fiddlerboy.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fiddlerboy.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fiddlerboy.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fiddlerboy.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fiddlerboy.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fiddlerboy.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fiddlerboy.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fiddlerboy.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fiddlerboy.wordpress.com&amp;blog=3660322&amp;post=83&amp;subd=fiddlerboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fiddlerboy.wordpress.com/2010/01/15/the-magic-of-bitmasks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/732364b215a9a8c161e68d2015a78b57?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">Fiddler</media:title>
		</media:content>
	</item>
		<item>
		<title>Gnuplot Cheat Codes</title>
		<link>http://fiddlerboy.wordpress.com/2010/01/15/gnuplot-cheat-codes/</link>
		<comments>http://fiddlerboy.wordpress.com/2010/01/15/gnuplot-cheat-codes/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 00:01:45 +0000</pubDate>
		<dc:creator>Fiddler</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[gnuplot]]></category>

		<guid isPermaLink="false">http://fiddlerboy.wordpress.com/?p=61</guid>
		<description><![CDATA[1. Disabling the X-axis 2. Disabling the Y-axis 3. Disabling the border 4. Plotting a circle 5. Ensuring that both axes use the same scale 6. Getting rid of legends<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fiddlerboy.wordpress.com&amp;blog=3660322&amp;post=61&amp;subd=fiddlerboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>1. Disabling the X-axis</strong></p>
<pre class="brush: plain;">
unset xtics
</pre>
<p><strong>2. Disabling the Y-axis</strong></p>
<pre class="brush: plain;">
unset ytics
</pre>
<p><strong>3. Disabling the border</strong></p>
<pre class="brush: plain;">
unset border
</pre>
<p><strong>4. Plotting a circle</strong></p>
<pre class="brush: plain;">
set parametric
plot sin(t), cos(t)
</pre>
<p><strong>5. Ensuring that both axes use the same scale</strong></p>
<pre class="brush: plain;">
set size square
</pre>
<p><strong>6. Getting rid of legends</strong></p>
<pre class="brush: plain;">
plot something notitle
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fiddlerboy.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fiddlerboy.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fiddlerboy.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fiddlerboy.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fiddlerboy.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fiddlerboy.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fiddlerboy.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fiddlerboy.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fiddlerboy.wordpress.com&amp;blog=3660322&amp;post=61&amp;subd=fiddlerboy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fiddlerboy.wordpress.com/2010/01/15/gnuplot-cheat-codes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/732364b215a9a8c161e68d2015a78b57?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">Fiddler</media:title>
		</media:content>
	</item>
	</channel>
</rss>
