Bit Logic > functions > select_bits
select_bits
Syntax:
  #include <boost/bit_logic/functions.hpp> 
  bit_handle select_bit ( BitStorage & bit_store, size_type bit_idx ) ; 
  bit_handle select_bits ( BitStorage & bit_store, size_type upper_bit_idx, size_type lower_bit_idx ) ; 
  const_bit_handle select_bit ( BitStorage const & bit_store, size_type bit_idx ) ; 
  const_bit_handle select_bits ( BitStorage const & bit_store, size_type upper_bit_idx, size_type lower_bit_idx ) ; 

The select_bits functions returns a Bit Handle that refers to some range of bits in a Bit Storage type. The naming diffence is used to denote selecting of 1 bit within a Bit Storage type as opposed to selecting a sequence of bits.

For example:

  uint16_t test_16 = 0xf00d ; 
  uint8_t test_8 = 0x0f; 						  
  uint32_t test_32 = 0xf0000000 ; 
  select_bits ( test_32, 31, 28 ) = select_bits ( test_8, 3, 0 ) ^ select_bits ( test_16, 15, 12 ) ; 
  cout << test_32 << endl ;

The above code creates two references to bit ranges in different bit_storage types. Those bits are logically xor'ed with each other and deposited back into the range specified on the left hand side of the equals sign.

  0

This code can throw the following exceptions :

Exceptions:
std::logic_error index range incorrect
bit_logic::out_of_bounds Indexing out of bounds of bit_storage type