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

CSharp examples for System:String Endian

Description

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

Demo Code


using System;/*  ww w  .j a  v  a  2s  . c  o m*/

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

         x ^= (x-1);
         // here  x == lowest_bit_01edge(x);
         return  ~(x>>1);
      }
}

Related Tutorials