<?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="https://betterexplained.com/articles/swap-two-variables-using-xor/feed/" rel="self" type="application/rss+xml" />
	<link>https://betterexplained.com/articles/swap-two-variables-using-xor/</link>
	<description>Math lessons that click</description>
	<lastBuildDate>Mon, 01 Aug 2022 23:00:39 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: SpartAlfresco		</title>
		<link>https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-568242</link>

		<dc:creator><![CDATA[SpartAlfresco]]></dc:creator>
		<pubDate>Mon, 01 Aug 2022 23:00:39 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-568242</guid>

					<description><![CDATA[&lt;blockquote&gt;&lt;p&gt;This is a cool trick, but don’t write this as an actual swap function.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;it doesnt like it because it fails when both variables are pointers to the same thing, but thats very rare and even so no high level language lets u use xor on anything but numerical types, which are not objects and could not have this problem.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The computer actually has an implicit “temp” variable that stores intermediate results before writing them back to a register.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;also it tries to act like it just uses a variable but in disguise, but having a value in a register is far different from as a variable, and the cost is negligible compare to having it in a variable.&lt;/p&gt;&lt;p&gt;i dont really like the criticisms of this. i mean its important to know the fail condition obviously, but it acts like its a deal breaker, which it really isnt. it just means u need to be careful whenever swapping two objects that might point to the same thing. or if you do it via a function, to check for the fail condition yourself, and just return immediately (which since they are the same essentially does the swap too).&lt;/p&gt;&lt;p&gt;also everyone saying using +/- and */÷ are ignoring the overflow that could happen, and also xor very easily scales, since if you do multiple bytes the xor is independent, theres no carry or borrow or anything.&lt;/p&gt;]]></description>
			<content:encoded><![CDATA[<blockquote><p>This is a cool trick, but don’t write this as an actual swap function.</p></blockquote>
<p>
it doesnt like it because it fails when both variables are pointers to the same thing, but thats very rare and even so no high level language lets u use xor on anything but numerical types, which are not objects and could not have this problem.
</p>
<blockquote><p>The computer actually has an implicit “temp” variable that stores intermediate results before writing them back to a register.</p></blockquote>
<p>
also it tries to act like it just uses a variable but in disguise, but having a value in a register is far different from as a variable, and the cost is negligible compare to having it in a variable.</p>
<p>i dont really like the criticisms of this. i mean its important to know the fail condition obviously, but it acts like its a deal breaker, which it really isnt. it just means u need to be careful whenever swapping two objects that might point to the same thing. or if you do it via a function, to check for the fail condition yourself, and just return immediately (which since they are the same essentially does the swap too).</p>
<p>also everyone saying using +/- and */÷ are ignoring the overflow that could happen, and also xor very easily scales, since if you do multiple bytes the xor is independent, theres no carry or borrow or anything.</p>
]]></content:encoded>
		
			</item>
	<item>
		<title>
		By: kalid		</title>
		<link>https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-567916</link>

		<dc:creator><![CDATA[kalid]]></dc:creator>
		<pubDate>Sun, 19 Jul 2020 22:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-567916</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-567913&quot;&gt;OooKhalid&lt;/a&gt;.

&lt;p&gt;Glad you enjoyed it!&lt;/p&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-567913">OooKhalid</a>.</p>
<p>Glad you enjoyed it!</p>
]]></content:encoded>
		
			</item>
	<item>
		<title>
		By: OooKhalid		</title>
		<link>https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-567913</link>

		<dc:creator><![CDATA[OooKhalid]]></dc:creator>
		<pubDate>Tue, 14 Jul 2020 12:24:26 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-567913</guid>

					<description><![CDATA[&lt;p&gt;what a wonderful example to showcase the wisdom of simplicity and secret presence of the ALU memory. thank you. i am a newbie and your blog gives me courage to trudge on.&lt;/p&gt;]]></description>
			<content:encoded><![CDATA[<p>what a wonderful example to showcase the wisdom of simplicity and secret presence of the ALU memory. thank you. i am a newbie and your blog gives me courage to trudge on.</p>
]]></content:encoded>
		
			</item>
	<item>
		<title>
		By: Paulami		</title>
		<link>https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-334359</link>

		<dc:creator><![CDATA[Paulami]]></dc:creator>
		<pubDate>Wed, 25 Jan 2017 10:30:41 +0000</pubDate>
		<guid isPermaLink="false">http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-334359</guid>

					<description><![CDATA[&lt;p&gt;Exactly, that&#039;s what I am confused about too. Swapping the pointers is not same as swapping the value at pointed address.&lt;/p&gt;]]></description>
			<content:encoded><![CDATA[<p>Exactly, that's what I am confused about too. Swapping the pointers is not same as swapping the value at pointed address.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
