fork(2) download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. unsigned get_last_n_bits( unsigned u, int n )
  6. {
  7. return u & ~(~0U << n);
  8. }
  9.  
  10. int main()
  11. {
  12. cout << bitset<8>(get_last_n_bits( 254, 2 ));
  13. return 0;
  14. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
00000010