<?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't hurt. Let's share the insights that made difficult ideas click.</description>
	<lastBuildDate>Fri, 20 Nov 2009 14:09:06 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>
	<item>
		<title>By: Anonymous</title>
		<link>http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-246911</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 23 Jun 2009 13:41:53 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-246911</guid>
		<description>Hi Kalid,
In response to Rich you said the following:

///////////////////
  Hi Rich, good question.

  When using pointers to the same location, when  you do the first step (x = x xor y) =&gt; 0 you also set y to 0 as well since it’s at the same location. In this case, you’ve lost the value 1234 — x and y were sharing the same location and it was overwritten with 0.

Hope this helps.

Kalid — July 17, 2008 @ 12:55 pm
//////

I&#039;m not able to understand why would pointer y change when pointer x changes. I think you meant
(*y) and (*x). Please Clarify.

Thanks.

RM</description>
		<content:encoded><![CDATA[<p>Hi Kalid,<br />
In response to Rich you said the following:</p>
<p>///////////////////<br />
  Hi Rich, good question.</p>
<p>  When using pointers to the same location, when  you do the first step (x = x xor y) =&gt; 0 you also set y to 0 as well since it’s at the same location. In this case, you’ve lost the value 1234 — x and y were sharing the same location and it was overwritten with 0.</p>
<p>Hope this helps.</p>
<p>Kalid — July 17, 2008 @ 12:55 pm<br />
//////</p>
<p>I&#8217;m not able to understand why would pointer y change when pointer x changes. I think you meant<br />
(*y) and (*x). Please Clarify.</p>
<p>Thanks.</p>
<p>RM</p>
]]></content:encoded>
	</item>
</channel>
</rss>
