snipt

Ctrl+h for KB shortcuts

C++

binary arith

n & (n-1) == true => n = 2^k
https://snipt.net/embed/75c1ce2538e005f40ca88270d7523da5/
/raw/75c1ce2538e005f40ca88270d7523da5/
75c1ce2538e005f40ca88270d7523da5
cpp
C++
1
2019-07-13T15:14:56
True
False
False
/api/public/snipt/34337/
binary-arith
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">n</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="nb">true</span> <span class="o">=&gt;</span> <span class="n">n</span> <span class="o">=</span> <span class="mi">2</span><span class="o">^</span><span class="n">k</span> </span></pre></div> </td></tr></table>
arith