Return word where a all bits from (including) the lowest set bit to bit 0 are set. - CSharp System

CSharp examples for System:String Endian

Description

Return word where a all bits from (including) the lowest set bit to bit 0 are set.

Demo Code


using System;//from   ww w  .jav a  2 s .com

public class Main{
    // Return word where a all bits from  (including) the
      //   lowest set bit to bit 0 are set.
      // Return 0 if no bit is set.
      public static UInt32 LowestBit01Edge( UInt32 x )
      {
         if( 0 == x )
            return 0;

         return  x^(x-1);
      }
}

Related Tutorials