mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-24 05:42:59 +08:00
Documentation for f7a5aecce5
This commit is contained in:
@@ -125,7 +125,7 @@ Functions</h2></td></tr>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p >Implementation to check whether a number is a power of 2 or not. </p>
|
||||
<p >This algorithm uses bit manipulation to check if a number is a power of 2 or not.</p>
|
||||
<h3><a class="anchor" id="autotoc_md77"></a>
|
||||
<h3><a class="anchor" id="autotoc_md78"></a>
|
||||
Algorithm</h3>
|
||||
<p >Let the input number be n, then the bitwise and between n and n-1 will let us know whether the number is power of 2 or not</p>
|
||||
<p >For Example, If N= 32 then N-1 is 31, if we perform bitwise and of these two numbers then the result will be zero, which indicates that it is the power of 2 If N=23 then N-1 is 22, if we perform bitwise and of these two numbers then the result will not be zero , which indicates that it is not the power of 2 </p><dl class="section note"><dt>Note</dt><dd>This implementation is better than naive recursive or iterative approach.</dd></dl>
|
||||
|
||||
Reference in New Issue
Block a user