<?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/"
	>

<channel>
	<title>exploration &#187; binary</title>
	<atom:link href="http://robertcarlsen.net/tag/binary/feed" rel="self" type="application/rss+xml" />
	<link>http://robertcarlsen.net</link>
	<description>accounts of success and misadventure</description>
	<lastBuildDate>Sat, 14 Aug 2010 21:49:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple things feel so good. (warning: geekery)</title>
		<link>http://robertcarlsen.net/2009/03/04/simple-things-feel-so-good-warning-geekery-541</link>
		<comments>http://robertcarlsen.net/2009/03/04/simple-things-feel-so-good-warning-geekery-541#comments</comments>
		<pubDate>Wed, 04 Mar 2009 05:57:25 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://robertcarlsen.net/blog/?p=541</guid>
		<description><![CDATA[Toggle an integer variable between 0 and 1. Useful for a flag to control program flow in C without boolean types.
toggleVar = 1&#62;&#62;toggleVar;
What this is doing is right shifting the integer 1 either zero or one place, depending on the current value of toggleVar.
An 8-bit (unsigned &#8211; positive values only) integer has 256 possible values. [...]]]></description>
			<content:encoded><![CDATA[<p>Toggle an integer variable between 0 and 1. Useful for a flag to control program flow in C without boolean types.</p>
<p>toggleVar = 1&gt;&gt;toggleVar;</p>
<p>What this is doing is right shifting the integer 1 either zero or one place, depending on the current value of toggleVar.</p>
<p>An 8-bit (unsigned &#8211; positive values only) integer has 256 possible values. This is a byte of information whose bits can be represented in binary as 00000000. The least significant bit, the smallest values are on the right&#8230;so, 00000001 = 1, 00000010 = 2 &#8230; 11111111 = 255.</p>
<p>Ok, this isn&#8217;t a binary lesson&#8230;so, right shifting is simply moving all the bits to columns to the right. 2&gt;&gt;1 = 1 or, 00000010 &gt;&gt; 1 = 00000001 (which is binary for 1).</p>
<p>The expression at the top does exactly this: When toggleVar is zero, it becomes 1&gt;&gt;0 = 1 and when toggleVar is 1 the expression is 1&gt;&gt;1 = 0. The last bit gets shifted right into oblivion!!! (sorry for that).</p>
<p>Of course, with boolean data types toggleVar = !toggleVar is still shorter, by one char! <img src='http://robertcarlsen.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://robertcarlsen.net/2009/03/04/simple-things-feel-so-good-warning-geekery-541/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
