I know >>
is Binary Right Shift Operator but what does >>=
mean, like if I want Log2 on x
I need while(x >>= 1) result++;
.
Asked
Active
Viewed 287 times
-3

Mano Mini
- 607
- 4
- 15
-
You could always try it out yourself... – Russ Schultz Oct 23 '15 at 14:08
-
`x >>= 1` is the short for `x = x >> 1;` – Spikatrix Oct 23 '15 at 14:10
-
2This question was already asked, here is the answer : http://stackoverflow.com/a/17769959/4811236 – Clément Béligat Oct 23 '15 at 14:12
-
There's nothing particularly interesting about this operator. If you want to think about something funky, consider `while( x --> 0 )`. – Bathsheba Oct 23 '15 at 14:13
-
wow.. you're bad people... @Olaf you can't search > in google. -paxdiablo I didn't see it. -Cool_Guy thanks. thanks everybody for the hate. – Mano Mini Oct 23 '15 at 14:18
-
@CoolGuy: It is not (exactly). The operand is only evaluated once, thus e.g. side-effects are only generated once, while for the assignment they would be twice. – too honest for this site Oct 23 '15 at 14:39
-
@Olaf Didn't knew that! Thanks! Is it the same for all shorthand operators like `-=`, `+=`, `*=` etc? – Spikatrix Oct 24 '15 at 12:25
-
@CoolGuy: http://port70.net/~nsz/c/c11/n1570.html – too honest for this site Oct 24 '15 at 12:48
-
@Olaf Umm. Could you tell me which section is it mentioned in? – Spikatrix Oct 24 '15 at 12:57
-
@CoolGuy: If your browser doesn't have a search-function, why not start with "assignment operators"? (giving a man a fish vs. teach him fishing ...) – too honest for this site Oct 24 '15 at 13:07
-
@Olaf Thanks. Got it. – Spikatrix Oct 24 '15 at 15:12
1 Answers
2
It's the bitwise shift right assignment operator; x >>= 1
is equivalent to x = x >> 1
.
(It has the same precedence as assignment =
).

Bathsheba
- 231,907
- 34
- 361
- 483