_popcnt32 ( a ) gives number of 1 's present in binary   representation of a.
string binaryString = Convert . ToString ( a , 2 ) ; int n = binaryString . Split ( new [ ] { '0' } , StringSplitOptions . RemoveEmptyEntries ) . Length + 1 ; return ( ( long ) Math . Pow ( 2 , n ) - 1 ) ; }