Find the lowest set bit in int number - Javascript Number Operation

Javascript examples for Number Operation:Bit Operation

Description

Find the lowest set bit in int number

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  w ww . j a  va 2 s  . c  o m
function filterFirstFoundBit(number)
{
    for (var i = 1; i < 32; i++) {
        if ((1 << i) & number)
        {
            return 1 << i;
        }
    }
    return number;
}
document.write(filterFirstFoundBit(10)); //01010
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials