Go Down

Topic: |= and += (Read 643 times) previous topic - next topic


Can anybody explain what is the difference between operators "|=" and "+=" when using them with registers?

For example, using "TIMSK+= 1<<1" works good, but "TIMSK|= 1<<1" kills delay command.


Jan 01, 2014, 09:32 am Last Edit: Jan 01, 2014, 09:39 am by pYro_65 Reason: 1
Addition is slightly different to or. Its no different to using chars, registers are just values too.

6 | 2 = 6
6 + 2 = 8

If you do not know what the operators are:
Forum Mod anyone?


Well, "+=" performs an addition, so if the bit you are trying to set is already 1, then its going to change to zero, and a 1 gets carried to the next most significant bit and so on. Not a suitable operation to perform on a control register, I would say.

"|=" performs logical OR, so if the bit in question is already 1 then no change is made.



Thanks a lot, I get it.

Go Up