How to determine what bits are set

Hello,
I am working on this project where when I receive a value and its 11th bit is set I need to do something in particular. With this being said, I want to know if there is a way I can check to see if a certain bit is set. I have tried bitset and left and right shift bitwise operators and nothing allowed me to check each bit one by one.

Thanks In Advance
1
2
3
4
5
6
unsigned long value ;
std::cin >> value ;
std::bitset< std::numeric_limits<unsigned long>::digits > bits(value) ;
std::cout << "these bits are set (lsb is bit zero): " ;
for( std::size_t i = 0 ; i < bits.size() ; ++i ) if( bits[i] )
    std::cout << i << ' ' ;
Thanks!! I got it working!!!
It can be simple done by using condition


if ( value & ( 1 << 10 ) ) { /* do something */ }
Topic archived. No new replies allowed.