<?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: Swap two variables using XOR</title>
	<atom:link href="http://betterexplained.com/articles/swap-two-variables-using-xor/feed/" rel="self" type="application/rss+xml" />
	<link>http://betterexplained.com/articles/swap-two-variables-using-xor/</link>
	<description>Learning shouldn&#039;t hurt. Let&#039;s share the insights that made difficult ideas click.</description>
	<lastBuildDate>Sun, 14 Mar 2010 21:58:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Anonymous</title>
		<link>http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-274254</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 27 Feb 2010 06:52:05 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-274254</guid>
		<description>void main()
{
int a=25,b=15;
a=a+b;
b=a-b;
a=a-b;
b=a+b;
printf(&quot;%d%d&quot;,a,b);
}</description>
		<content:encoded><![CDATA[<p>void main()<br />
{<br />
int a=25,b=15;<br />
a=a+b;<br />
b=a-b;<br />
a=a-b;<br />
b=a+b;<br />
printf(&#8221;%d%d&#8221;,a,b);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sriram</title>
		<link>http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-262478</link>
		<dc:creator>Sriram</dc:creator>
		<pubDate>Sun, 15 Nov 2009 04:30:17 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-262478</guid>
		<description>Hey guys, what about swaping variables contains string values? All of your solutions will suck... Try this and swap integer or string without third variable... Happy Sensible Coding..

$v = &#039;sriram&#039;;
$u = &#039;lakshmi&#039;;

$v .= $u;
$u = substr($v,0,(strlen($v) - strlen($u)));
$v = substr($v,(strlen($v) - strlen($u)-1), strlen($v));

echo &#039;u = &#039; . $u .&#039;&#039;;
echo &#039;v = &#039; . $v;</description>
		<content:encoded><![CDATA[<p>Hey guys, what about swaping variables contains string values? All of your solutions will suck&#8230; Try this and swap integer or string without third variable&#8230; Happy Sensible Coding..</p>
<p>$v = &#8217;sriram&#8217;;<br />
$u = &#8216;lakshmi&#8217;;</p>
<p>$v .= $u;<br />
$u = substr($v,0,(strlen($v) &#8211; strlen($u)));<br />
$v = substr($v,(strlen($v) &#8211; strlen($u)-1), strlen($v));</p>
<p>echo &#8216;u = &#8216; . $u .&#8221;;<br />
echo &#8216;v = &#8216; . $v;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-261233</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 02 Nov 2009 00:22:25 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-261233</guid>
		<description>Well I&#039;m not getting one single exchange instruction... at least in debugging mode. This is what I see in my VC++ 6 dissassembly window:

45:           a.i ^= b.i;
00401450   mov         edx,dword ptr [a]
00401453   xor         edx,dword ptr [b]
00401456   mov         dword ptr [a],edx
46:           b.i = a.i^b.i;
00401459   mov         eax,dword ptr [a]
0040145C   xor         eax,dword ptr [b]
0040145F   mov         dword ptr [b],eax
47:           a.i ^= b.i;
00401462   mov         ecx,dword ptr [a]
00401465   xor         ecx,dword ptr [b]
00401468   mov         dword ptr [a],ecx
48:
49:           t = y;
0040146B   mov         edx,dword ptr [y]
0040146E   mov         dword ptr [t],edx
50:           y = x;
00401471   mov         eax,dword ptr [x]
00401474   mov         dword ptr [y],eax
51:           x = t;
00401477   mov         ecx,dword ptr [t]
0040147A   mov         dword ptr [x],ecx


&#039;a&#039; and &#039;b&#039; are what I call &quot;flints,&quot; a union containing a float and int.</description>
		<content:encoded><![CDATA[<p>Well I&#8217;m not getting one single exchange instruction&#8230; at least in debugging mode. This is what I see in my VC++ 6 dissassembly window:</p>
<p>45:           a.i ^= b.i;<br />
00401450   mov         edx,dword ptr [a]<br />
00401453   xor         edx,dword ptr [b]<br />
00401456   mov         dword ptr [a],edx<br />
46:           b.i = a.i^b.i;<br />
00401459   mov         eax,dword ptr [a]<br />
0040145C   xor         eax,dword ptr [b]<br />
0040145F   mov         dword ptr [b],eax<br />
47:           a.i ^= b.i;<br />
00401462   mov         ecx,dword ptr [a]<br />
00401465   xor         ecx,dword ptr [b]<br />
00401468   mov         dword ptr [a],ecx<br />
48:<br />
49:           t = y;<br />
0040146B   mov         edx,dword ptr [y]<br />
0040146E   mov         dword ptr [t],edx<br />
50:           y = x;<br />
00401471   mov         eax,dword ptr [x]<br />
00401474   mov         dword ptr [y],eax<br />
51:           x = t;<br />
00401477   mov         ecx,dword ptr [t]<br />
0040147A   mov         dword ptr [x],ecx</p>
<p>&#8216;a&#8217; and &#8216;b&#8217; are what I call &#8220;flints,&#8221; a union containing a float and int.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
