<?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: Toggle an Integer Between 1 and 0</title>
	<atom:link href="http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html</link>
	<description>iOS Developer Tips, Tricks and Tutorials.</description>
	<lastBuildDate>Wed, 08 Feb 2012 06:31:16 -0600</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: root</title>
		<link>http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html#comment-10982</link>
		<dc:creator>root</dc:creator>
		<pubDate>Fri, 12 Mar 2010 10:03:35 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2157#comment-10982</guid>
		<description>bitwise operations like ^ tend to be significantly faster than other operations.</description>
		<content:encoded><![CDATA[<p>bitwise operations like ^ tend to be significantly faster than other operations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pascal</title>
		<link>http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html#comment-1602</link>
		<dc:creator>Pascal</dc:creator>
		<pubDate>Mon, 04 May 2009 10:11:31 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2157#comment-1602</guid>
		<description>If you&#039;re using the int as a kind of flag...

You might remember your end of last year: http://iphonedevelopertips.com/objective-c/of-bool-and-yes.html

 BOOL is nothing else than a signed char, and YES is defined as 1 (NO is 0), you can even write:

static int x = 0;
 
  // Toggles 1 to 0 and 0 to 1 using !
  x = ! x;</description>
		<content:encoded><![CDATA[<p>If you&#8217;re using the int as a kind of flag&#8230;</p>
<p>You might remember your end of last year: <a href="http://iphonedevelopertips.com/objective-c/of-bool-and-yes.html" rel="nofollow">http://iphonedevelopertips.com/objective-c/of-bool-and-yes.html</a></p>
<p> BOOL is nothing else than a signed char, and YES is defined as 1 (NO is 0), you can even write:</p>
<p>static int x = 0;</p>
<p>  // Toggles 1 to 0 and 0 to 1 using !<br />
  x = ! x;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html#comment-1511</link>
		<dc:creator>john</dc:creator>
		<pubDate>Fri, 01 May 2009 19:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2157#comment-1511</guid>
		<description>Another way is this:

x = 1 - x;

If x is 1, it is now 0. If it was 0, it&#039;s now 1. Pretty much the same thing as using XOR, but much simpler to understand.</description>
		<content:encoded><![CDATA[<p>Another way is this:</p>
<p>x = 1 &#8211; x;</p>
<p>If x is 1, it is now 0. If it was 0, it&#8217;s now 1. Pretty much the same thing as using XOR, but much simpler to understand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seventoes</title>
		<link>http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html#comment-1419</link>
		<dc:creator>seventoes</dc:creator>
		<pubDate>Tue, 28 Apr 2009 21:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2157#comment-1419</guid>
		<description>Same as using a bool and doing..

BOOL someBool = NO;

someBool = !someBool;

//someBool is now YES</description>
		<content:encoded><![CDATA[<p>Same as using a bool and doing..</p>
<p>BOOL someBool = NO;</p>
<p>someBool = !someBool;</p>
<p>//someBool is now YES</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://iPhoneDeveloperTips.com/c/toggle-an-integer-between-1-and-0.html#comment-1418</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 28 Apr 2009 21:25:05 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2157#comment-1418</guid>
		<description>Pretty handy to use this with the bitfields from a previous post of yours.


typedef struct {
	unsigned preLoaded;
	unsigned saveState;
	unsigned saveLoginName;
} SomeStatus;


		SomeStatus status;
		status.preLoaded = 1;
		status.saveState = 0;
		status.saveLoginName = 1;
		
		status.preLoaded ^= 1;
		
		if( status.preLoaded == 0 )
			NSLog(@&quot;preloaded is off&quot;);
		else
			NSLog(@&quot;preloaded is on&quot;);
		
		if( status.saveState == 0 )
			NSLog(@&quot;saveState is off&quot;);
		else
			NSLog(@&quot;saveState is on&quot;);
		
		if( status.saveLoginName == 0 )
			NSLog(@&quot;saveLoginName is off&quot;);
		else
			NSLog(@&quot;saveLoginName is on&quot;);</description>
		<content:encoded><![CDATA[<p>Pretty handy to use this with the bitfields from a previous post of yours.</p>
<p>typedef struct {<br />
	unsigned preLoaded;<br />
	unsigned saveState;<br />
	unsigned saveLoginName;<br />
} SomeStatus;</p>
<p>		SomeStatus status;<br />
		status.preLoaded = 1;<br />
		status.saveState = 0;<br />
		status.saveLoginName = 1;</p>
<p>		status.preLoaded ^= 1;</p>
<p>		if( status.preLoaded == 0 )<br />
			NSLog(@&#8221;preloaded is off&#8221;);<br />
		else<br />
			NSLog(@&#8221;preloaded is on&#8221;);</p>
<p>		if( status.saveState == 0 )<br />
			NSLog(@&#8221;saveState is off&#8221;);<br />
		else<br />
			NSLog(@&#8221;saveState is on&#8221;);</p>
<p>		if( status.saveLoginName == 0 )<br />
			NSLog(@&#8221;saveLoginName is off&#8221;);<br />
		else<br />
			NSLog(@&#8221;saveLoginName is on&#8221;);</p>
]]></content:encoded>
	</item>
</channel>
</rss>

