apps/matlab/slots.c
uint32_t BitIndex(uint32_t nslots_mask, uint32_t n, slot_mode_t mode) {

    assert(n && (! (n & (n-1)) )); // single bit set
    assert(n & nslots_mask); // bit set is within ROI
    
    uint32_t idx = BitPosition(n);
    uint32_t slot_mask =  (((uint32_t)~0UL >> (sizeof(uint32_t) * 8 - idx)));
    uint32_t remaining_mask = ((uint32_t)~0UL << idx);
        
    if (mode == SLOT_POSITION)
        return NumberOfBits(nslots_mask & slot_mask) - 1; // slot position
    else
        return NumberOfBits(nslots_mask & remaining_mask) - 1; // no. of slots remaining
}
/**
 * Help function to calculate the numerical ordering of a bit within a bitmask
 *
 * @param n bitfield
 * @param mask
 * @return numerical ordering of a bit witin bitmask.
 */
Help function to calculate the numerical ordering of a bit within a bitmask
@param n bitfield
@param mask
@return numerical ordering of a bit witin bitmask.
Help function to calculate the numerical ordering of a bit within a bitmask @param n bitfield @param mask @return numerical ordering of a bit witin bitmask .
uint32_t BitIndex(uint32_t nslots_mask, uint32_t n, slot_mode_t mode) {
    assert(n && (! (n & (n-1)) )); 
    assert(n & nslots_mask); 
    uint32_t idx = BitPosition(n);
    uint32_t slot_mask =  (((uint32_t)~0UL >> (sizeof(uint32_t) * 8 - idx)));
    uint32_t remaining_mask = ((uint32_t)~0UL << idx);
    if (mode == SLOT_POSITION)
        return NumberOfBits(nslots_mask & slot_mask) - 1; 
    else
        return NumberOfBits(nslots_mask & remaining_mask) - 1; 
}
uint32_t BitIndex ( uint32_t nslots_mask , uint32_t n , slot_mode_t mode ) { assert ( n && ( ! ( n & ( n - 1 ) ) ) ) ; assert ( n & nslots_mask ) ; uint32_t idx = BitPosition ( n ) ; uint32_t slot_mask = ( ( ( uint32_t ) ~ 0UL >> ( sizeof ( uint32_t ) * 8 - idx ) ) ) ; uint32_t remaining_mask = ( ( uint32_t ) ~ 0UL << idx ) ; if ( mode == SLOT_POSITION ) return NumberOfBits ( nslots_mask & slot_mask ) - 1 ; else return NumberOfBits ( nslots_mask & remaining_mask ) - 1 ; }
Help function to calculate the numerical ordering of a bit within a bitmask
 @param n bitfield
 @param mask
 @return numerical ordering of a bit witin bitmask.
Help function to calculate the numerical ordering of a bit within a bitmask @param n bitfield @param mask @return numerical ordering of a bit witin bitmask .
// single bit set // bit set is within ROI // slot position // no. of slots remaining