<?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: Double bitwise NOT (~~)</title>
	<atom:link href="http://james.padolsey.com/javascript/double-bitwise-not/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com/javascript/double-bitwise-not/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:03:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Art</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-31694</link>
		<dc:creator>Art</dc:creator>
		<pubDate>Mon, 07 Feb 2011 19:08:39 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-31694</guid>
		<description>I meant not going to work. (typo)</description>
		<content:encoded><![CDATA[<p>I meant not going to work. (typo)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Art</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-31693</link>
		<dc:creator>Art</dc:creator>
		<pubDate>Mon, 07 Feb 2011 19:08:01 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-31693</guid>
		<description>~~ is going to work as Math.floor for negative numbers.

~~(-2.999) = -2
Math.floor(-2.999) = -3</description>
		<content:encoded><![CDATA[<p>~~ is going to work as Math.floor for negative numbers.</p>
<p>~~(-2.999) = -2<br />
Math.floor(-2.999) = -3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathias Bynens</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-29617</link>
		<dc:creator>Mathias Bynens</dc:creator>
		<pubDate>Sun, 01 Aug 2010 09:09:43 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-29617</guid>
		<description>Note that bitwise operators convert numbers to a 32-bit sequence before processing them, so the range is different.

Alternatives to &lt;code&gt;Math.floor&lt;/code&gt; using bitwise operators will only work with positive signed 32-bit floats, i.e. numbers from 0 to +2,147,483,647 (2^31-1).

&lt;pre&gt;&lt;code&gt;~~2147483647.1; // 2147483647
~~2147483648.1; // -2147483648&lt;/code&gt;&lt;/pre&gt;

I’ve created &lt;a href=&quot;http://jsperf.com/rounding-numbers-down&quot; title=&quot;jsPerf: Rounding numbers down&quot;&gt;a jsPerf test case&lt;/a&gt; to benchmark these different approaches. Feel free to add more possibilities!</description>
		<content:encoded><![CDATA[<p>Note that bitwise operators convert numbers to a 32-bit sequence before processing them, so the range is different.</p>
<p>Alternatives to <code>Math.floor</code> using bitwise operators will only work with positive signed 32-bit floats, i.e. numbers from 0 to +2,147,483,647 (2^31-1).</p>
<pre><code>~~2147483647.1; // 2147483647
~~2147483648.1; // -2147483648</code></pre>
<p>I’ve created <a href="http://jsperf.com/rounding-numbers-down" title="jsPerf: Rounding numbers down">a jsPerf test case</a> to benchmark these different approaches. Feel free to add more possibilities!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-28594</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Mon, 19 Apr 2010 12:29:23 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-28594</guid>
		<description>Or you could add 0.5 and have Math.round() and by adding 1 you&#039;d have Math.ceil();

Math.floor(x) == ~~(x)
Math.round(x) ==  ~~(x + 0.5)
Math.ceil(x) ==  ~~(x + 1)

Cheers,
Tom</description>
		<content:encoded><![CDATA[<p>Or you could add 0.5 and have Math.round() and by adding 1 you&#8217;d have Math.ceil();</p>
<p>Math.floor(x) == ~~(x)<br />
Math.round(x) ==  ~~(x + 0.5)<br />
Math.ceil(x) ==  ~~(x + 1)</p>
<p>Cheers,<br />
Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Kirk</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-28349</link>
		<dc:creator>Martin Kirk</dc:creator>
		<pubDate>Fri, 16 Apr 2010 08:39:41 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-28349</guid>
		<description>@Carlos

ahhh -- yes you are right !</description>
		<content:encoded><![CDATA[<p>@Carlos</p>
<p>ahhh &#8212; yes you are right !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-28348</link>
		<dc:creator>Carlos</dc:creator>
		<pubDate>Fri, 16 Apr 2010 08:35:30 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-28348</guid>
		<description>@Martin Kirk My question remains, shouldn&#039;t this line

var SelectedOptions = Option3 &amp; Option6 &amp; Option10; //= 1000100100

be

var SelectedOptions = Option3 &#124; Option6 &#124; Option10; //= 1000100100</description>
		<content:encoded><![CDATA[<p>@Martin Kirk My question remains, shouldn&#8217;t this line</p>
<p>var SelectedOptions = Option3 &amp; Option6 &amp; Option10; //= 1000100100</p>
<p>be</p>
<p>var SelectedOptions = Option3 | Option6 | Option10; //= 1000100100</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Kirk</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-28344</link>
		<dc:creator>Martin Kirk</dc:creator>
		<pubDate>Fri, 16 Apr 2010 07:44:37 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-28344</guid>
		<description>@Carlos

sorry... the HTML formatting has been fixed</description>
		<content:encoded><![CDATA[<p>@Carlos</p>
<p>sorry&#8230; the HTML formatting has been fixed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Kirk</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-28342</link>
		<dc:creator>Martin Kirk</dc:creator>
		<pubDate>Fri, 16 Apr 2010 07:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-28342</guid>
		<description>@Carlos

what&#039;s up with the &amp; ??? 
the bitwise operator is &#039;&amp;&#039;</description>
		<content:encoded><![CDATA[<p>@Carlos</p>
<p>what&#8217;s up with the &amp; ???<br />
the bitwise operator is &#8216;&amp;&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SJL Web Design</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-28329</link>
		<dc:creator>SJL Web Design</dc:creator>
		<pubDate>Thu, 15 Apr 2010 19:12:01 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-28329</guid>
		<description>Great article, thanks to Martin for his additional pieces of code too.</description>
		<content:encoded><![CDATA[<p>Great article, thanks to Martin for his additional pieces of code too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlos</title>
		<link>http://james.padolsey.com/javascript/double-bitwise-not/comment-page-1/#comment-27402</link>
		<dc:creator>carlos</dc:creator>
		<pubDate>Thu, 25 Mar 2010 16:04:10 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1433#comment-27402</guid>
		<description>Shouldn&#039;t @Martin Kirk example be:

&lt;pre lang=&quot;javascript&quot;&gt;
var Option1 = 2
var Option2 = 4
var Option3 = 8
var Option4 = 16
var Option10 = 1024

var SelectedOptions = Option3 &#124; Option6 &#124; Option10; //= 1000100100

if(Option6 &amp; SelectedOptions) {
    doSomething()
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Shouldn&#8217;t @Martin Kirk example be:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> Option1 <span class="sy0">=</span> <span class="nu0">2</span>
<span class="kw2">var</span> Option2 <span class="sy0">=</span> <span class="nu0">4</span>
<span class="kw2">var</span> Option3 <span class="sy0">=</span> <span class="nu0">8</span>
<span class="kw2">var</span> Option4 <span class="sy0">=</span> <span class="nu0">16</span>
<span class="kw2">var</span> Option10 <span class="sy0">=</span> <span class="nu0">1024</span>
&nbsp;
<span class="kw2">var</span> SelectedOptions <span class="sy0">=</span> Option3 <span class="sy0">|</span> Option6 <span class="sy0">|</span> Option10<span class="sy0">;</span> <span class="co1">//= 1000100100</span>
&nbsp;
<span class="kw1">if</span><span class="br0">&#40;</span>Option6 <span class="sy0">&amp;</span>amp<span class="sy0">;</span> SelectedOptions<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    doSomething<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
</channel>
</rss>

