Re: Strange Operator

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 03/31/04


Date: Wed, 31 Mar 2004 22:32:34 +1000


"Simon Lewis" <sheepboy69uk@NOSPAMyahoo.com> wrote in message
news:c4eans$8q1$1@wotsit.aston.ac.uk...
| Dear All,
|
| I have been stepping though some code, and came across the following
| operator:
|
| value >>= 1;
|
| (value is an int)
|
| It seems to be assigning 1 to value, could anyone shed some light on its
| meaning?

It is a 'bitwise - right-shift' operator.

It's affect is to shift all bit's to the right, by the
nominated value. For example:

int value = 10;
value >>= 1;

...would look like this:

// 00001010
// 00000101 == 5

Btw, when combined with the assignment operator '=', it
is known as an compound operator, which performs the shift
and assignment within the same expression.

Cheers.
Chris Val



Relevant Pages

  • Re: why does C standard allow this declaration
    ... "b" is defined at line 4 but the assignment at line 5 is skipped. ... when the control flow of the program "passes through" that statement. ... int silly_func ... The first line inside the brace is a declaration with an initializer, ...
    (comp.lang.c)
  • Re: bitshifting
    ... Is that 32 bits for an int and a byte for a char? ... the sign but not necessarily the signedness. ... signed shift can be undefined. ... Shifts are defined in terms of what they do to the value (multiplying ...
    (comp.lang.c)
  • Re: why still use C?
    ... I was talking about the malloc expression, ... >>the assignment expression. ... >>enum parameter is not an error in C, but in my coding style it's a mistake). ... I took it you meant "int where an enum" is expected, ...
    (comp.lang.c)
  • Re: Return statement twice in the same expression
    ... > int main{ ... One of these imperatives is `return', ... The expression happens to contain the assignment operator ... thing you can do with a `void' value is ignore it. ...
    (comp.lang.c)
  • Re: [PATCH 1/2] fb: add support for foreign endianness
    ... This is done via FBINFO_FOREIGN_ENDIAN flag that will ... Depending on the host endianness this flag ... int left, right; ... if (!shift) { ...
    (Linux-Kernel)