int getIndexOfBit ( int n ) { // return __builtin_popcountll(value & ~(0xffffffffffffffffULL >> n)); int numMarkedBits = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( hasBit ( i ) ) { numMarkedBits ++ ; } } return numMarkedBits ; }
Gets the index of the specified bit in the set which is the number of marked bits that appear before the specified bit .