<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.7" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: I&#8217;ve Got the Power (of 2)</title>
	<link>http://www.technicalinterviews.net/ive-got-the-power-of-2/</link>
	<description>This site features a collection of common technical interview questions gathered by a group of programmers who have been through, and given, lots of technical interviews. There is an emphasis on C++ and game programming technical interviews, but most of the questions are relevant to any technical interview.</description>
	<pubDate>Thu, 04 Dec 2008 19:20:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.7</generator>

	<item>
		<title>by: Toddsa</title>
		<link>http://www.technicalinterviews.net/ive-got-the-power-of-2/#comment-150</link>
		<pubDate>Sun, 04 Mar 2007 23:14:03 +0000</pubDate>
		<guid>http://www.technicalinterviews.net/ive-got-the-power-of-2/#comment-150</guid>
					<description>given x as an integer

(x &#38; (x-1)) will be 0 if x is a power of 2 and non zero if it is not. The reason is all power of 2's in binary will have a single set bit and (x-1) will have all set bits excluding x. for example x = 8 in binary is 1000 and (x-1) or 7 in binary is 111 so if you use the &#38; operator you will get. 

  1000
&#38; 0111
------
  0000

Any x this is not a power of 2 will result in some other non 0 result.</description>
		<content:encoded><![CDATA[<p>given x as an integer</p>
<p>(x &amp; (x-1)) will be 0 if x is a power of 2 and non zero if it is not. The reason is all power of 2&#8217;s in binary will have a single set bit and (x-1) will have all set bits excluding x. for example x = 8 in binary is 1000 and (x-1) or 7 in binary is 111 so if you use the &amp; operator you will get. </p>
<p>  1000<br />
&amp; 0111<br />
&#8212;&#8212;<br />
  0000</p>
<p>Any x this is not a power of 2 will result in some other non 0 result.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Robin</title>
		<link>http://www.technicalinterviews.net/ive-got-the-power-of-2/#comment-45</link>
		<pubDate>Thu, 01 Feb 2007 21:40:45 +0000</pubDate>
		<guid>http://www.technicalinterviews.net/ive-got-the-power-of-2/#comment-45</guid>
					<description>This will be 0 if only one bit. 
otherwise, it is non-zero.</description>
		<content:encoded><![CDATA[<p>This will be 0 if only one bit.<br />
otherwise, it is non-zero.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Robin</title>
		<link>http://www.technicalinterviews.net/ive-got-the-power-of-2/#comment-44</link>
		<pubDate>Thu, 01 Feb 2007 21:39:43 +0000</pubDate>
		<guid>http://www.technicalinterviews.net/ive-got-the-power-of-2/#comment-44</guid>
					<description>I could not put in the leftshit operator. 

  Answer is:

  X leftshift by 1 bit &#38;
  X leftshift by 2 bits &#38;
  X leftshift by 3 bits</description>
		<content:encoded><![CDATA[<p>I could not put in the leftshit operator. </p>
<p>  Answer is:</p>
<p>  X leftshift by 1 bit &amp;<br />
  X leftshift by 2 bits &amp;<br />
  X leftshift by 3 bits
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
