How to set all even bits of a number to zero (0) in C++

1 Answer

0 votes
#include <iostream>
#include <bitset>
   
using namespace std;

int main() 
{
    int n = 255;
       
    cout << bitset<8>(n) << endl;
     
    n = n & 0xaaaaaaaa;
     
    cout << bitset<8>(n) << endl;
       
    return 0;
}
  
  
   
/*
run:
   
11111111
10101010
   
*/

 



answered Mar 20, 2019 by avibootz

Related questions

1 answer 197 views
1 answer 207 views
207 views asked Jul 17, 2018 by avibootz
1 answer 220 views
1 answer 69 views
1 answer 99 views
...