compound assignment operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vasileios Zografos

    compound assignment operator

    Can someone please tell me what this assignment does?


    iType |= EB_YMIN_ZMAX;

  • Victor Bazarov

    #2
    Re: compound assignment operator

    "Vasileios Zografos" <vzografos@bcs. org.uk> wrote...[color=blue]
    > Can someone please tell me what this assignment does?
    >
    >
    > iType |= EB_YMIN_ZMAX;
    >[/color]

    The same as

    iType = iType | EB_YMIN_ZMAX;

    with the exception that 'iType' is only evaluated once.

    Victor


    Comment

    • Vasileios Zografos

      #3
      Re: compound assignment operator

      Victor Bazarov wrote:[color=blue]
      > "Vasileios Zografos" <vzografos@bcs. org.uk> wrote...
      >[color=green]
      >>Can someone please tell me what this assignment does?
      >>
      >>
      >>iType |= EB_YMIN_ZMAX;
      >>[/color]
      >
      >
      > The same as
      >
      > iType = iType | EB_YMIN_ZMAX;
      >
      > with the exception that 'iType' is only evaluated once.
      >
      > Victor
      >
      >[/color]

      Trying not to sound too ignorant....
      what does | do?

      Comment

      • Victor Bazarov

        #4
        Re: compound assignment operator

        "Vasileios Zografos" <vzografos@bcs. org.uk> wrote...[color=blue]
        > Victor Bazarov wrote:[color=green]
        > > "Vasileios Zografos" <vzografos@bcs. org.uk> wrote...
        > >[color=darkred]
        > >>Can someone please tell me what this assignment does?
        > >>
        > >>
        > >>iType |= EB_YMIN_ZMAX;
        > >>[/color]
        > >
        > >
        > > The same as
        > >
        > > iType = iType | EB_YMIN_ZMAX;
        > >
        > > with the exception that 'iType' is only evaluated once.
        > >
        > > Victor
        > >
        > >[/color]
        >
        > Trying not to sound too ignorant....
        > what does | do?
        >[/color]

        It's what is known as "bitwise OR". Every pair of corresponding
        bits in the operands is 'or'ed to produce the corresponding bit
        in the result. Example:

        010100101001110 101 | 000100010101101 001 => 010100111101111 101

        Victor


        Comment

        • Thomas Matthews

          #5
          Re: compound assignment operator

          Vasileios Zografos wrote:[color=blue]
          > Victor Bazarov wrote:
          >[color=green]
          >> "Vasileios Zografos" <vzografos@bcs. org.uk> wrote...
          >>[color=darkred]
          >>> Can someone please tell me what this assignment does?
          >>>
          >>>
          >>> iType |= EB_YMIN_ZMAX;
          >>>[/color]
          >>
          >>
          >> The same as
          >>
          >> iType = iType | EB_YMIN_ZMAX;
          >>
          >> with the exception that 'iType' is only evaluated once.
          >>
          >> Victor
          >>
          >>[/color]
          >
          > Trying not to sound too ignorant....
          > what does | do?
          >[/color]

          Bitwise OR:

          A B A OR B
          --- --- ------
          0 0 0
          0 1 1
          1 0 1
          1 1 1

          The bitwise-OR operator is often used to "set" bits.

          --
          Thomas Matthews

          C++ newsgroup welcome message:

          C++ Faq: http://www.parashift.com/c++-faq-lite
          C Faq: http://www.eskimo.com/~scs/c-faq/top.html
          alt.comp.lang.l earn.c-c++ faq:

          Other sites:
          http://www.josuttis.com -- C++ STL Library book

          Comment

          Working...