❔ Practical use for bitwise operators, specifically |= in context.
Not bitwise application. This is a simple boolean or equals
Howdy folks. Currently working in a new codebase with a lot of legacy code and 0 of the folks that wrote it still around. To preface I ran into this bit of code and am failing to truly understand what it's doing.
Now I do understand the basics of bit-level operators and how they function at the operator level (bit column comparisons resulting in a new binary representation ). I've just never ran into them in production, and honestly might still be too "green" with them to understand what they're doing exactly. Happy to give more context, but as it stands I'm uncertain of the dev was trying to achieve here.
7 Replies
This actually looks to be boolean overriding? May delete after some tests here
does the same as
It's not bitwise - it's a boolean 'or equals'
yeah, it's like
||
except it always evaluated both sidesThere's no
||=
, so they probably reached for |=
, even though it's a bit less efficient in this case as it will always evaluate GetCategoryCount(currentType) == 1
regardless of whether myFlag
is true or falseThank you so much. I know this is a rather simple one. But it looked a bit strange to me.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.