Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does |= operator do? [duplicate]

Tags:

c#

Possible Duplicate:
what does |= (single pipe equal) and &=(single ampersand equal) mean in c# (csharp)

Here is the context where it is being used:

long dirtyFlag = 0x0000;

if (erd.SupervisorCompType != orgErd.SupervisorCompType) // change has been made?
{
   dirtyFlag |= 0x0001;
   // etc...
}
like image 647
Sam Avatar asked Mar 18 '26 13:03

Sam


1 Answers

dirtyFlag |= 0x0001 is equivalent to dirtyFlag = dirtyFlag | 0x0001. The | operator is the bitwise OR operator. In your case, it sets the lowest binary bit. Some further examples:

1 | 2 = 3 (0001 | 0010 = 0011)
2 | 4 = 6 (0010 | 0100 = 0110)
5 | 1 = 5 (0101 | 0001 = 0101)
like image 77
CrazyCasta Avatar answered Mar 21 '26 02:03

CrazyCasta