What does & = mean in lens c?

Today I came across this piece of code:

indexValid &= x >= 0;

What does & = mean? Can someone explain what is happening in this statement?

+4
source share
2 answers

This is not about Objective-C, but regular C.

Here the operator with the operator is &=equivalent indexValid = indexValid & (x >= 0). The operator itself &is called bitwise and operator, and AND- operands. This means that returns 1only if both operands 1, else returns 0if either operand is not 1. ANDing and ORing are commonly used when setting flags in software.

, indexValid 0011010 , AND (x >= 0) ( , 1, 0), 0000000 (, x >= 0 1), 0011010 & 0000001 0000000.

, http://en.wikipedia.org/wiki/Boolean_logic - .

+7

bitwise AND assignment operator ( ' ').

bitwise AND .

x&= y;

x= x & y; 
+2

All Articles