Return word where all the (low end) ones are set - CSharp System

CSharp examples for System:String Endian

Description

Return word where all the (low end) ones are set

Demo Code


using System;/*from w w  w  .  j a  va2s  . c  o m*/

public class Main{
    // Return word where all the (low end) ones are set.
      // Example:  01011011 --> 00000011
      // Return 0 if lowest bit is zero:
      //       10110110 --> 0
      public static UInt32 LowBits( UInt32 x )
      {
         if( ~0U == x )
            return ~0U;

         return (((x+1)^x) >> 1);
      }
}

Related Tutorials