What does |= mean in c++? -
this question has answer here:
- a sign in c++ i've never seen before: |= 5 answers
i trying understand |= in c++, have sample code
int x = 0 ; x |= 3; std::cout<<x <<std::endl; x |= 6; std::cout<<x <<std::endl; output :
3 7 how possible, related bit addition??
its bitwise or.
first case:
0011(3 in decimal) 0000(0 in decimal) so, or of both is:
0011 or 0000 = 0011 = 2^0 + 2^1 = 3 for second case, or works follows:
0011 (3 in decimal) 0110 (6 in decimal) output of or 0111 in decimal is:
0011 or 0110 = 0111 = 2^0 + 2^1 + 2^2 = 1+2+4 = 7
Comments
Post a Comment