The & is comparing the bits of the 2 values.
The 1st comparison is with 1 so 00000000 00000000 00000000 00000001 .
If the value in state has the last bit fired up , regardless of value , the & comparison will result in a 1 too because it fires up the bits that are 1s on both values
It's like looking at the uint as a board of switches
If you define A=1, B=2, and C=4. Then a value of 7 means all three are set. A value of 5 means A and C are set, but B is not.
(state&1) == 1 means is the first bit set, meaning A is one (true), second and third bits are irrelevant.
state == 1 means the first bit is true, and the others are not. Completely different and wrong.
Hi.
Can anyone explain to me why they have used (state& 1) == 1 not state == 1 nor sparam == "1" in the below sample? What's the advantage of using bitwise operation here, and why we shouldn't use other samples? Thank you
https://www.mql5.com/en/docs/constants/chartconstants/enum_chartevents
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi.
Can anyone explain to me why they have used (state& 1) == 1 not state == 1 nor sparam == "1" in the below sample? What's the advantage of using bitwise operation here, and why we shouldn't use other samples? Thank you
https://www.mql5.com/en/docs/constants/chartconstants/enum_chartevents