^=

Discussion in 'Java' started by RVic, Jul 29, 2009.

  1. RVic

    RVic Guest

    What does the operator:

    ^=

    do?

    I have it used in code I am working with as:

    byte u = 0x00;
    for(int i = 0; i < msg.length(); i++) {
    // ASSUMES: ASCII
    u ^= (byte)msg.charAt(i);
    }
    u ^= 0x03;

    //thx
    RVic, Jul 29, 2009
    #1
    1. Advertising

  2. RVic

    Lars Enderin Guest

    RVic wrote:
    > What does the operator:
    >
    > ^=
    >
    > do?
    >
    > I have it used in code I am working with as:
    >
    > byte u = 0x00;
    > for(int i = 0; i < msg.length(); i++) {
    > // ASSUMES: ASCII
    > u ^= (byte)msg.charAt(i);
    > }
    > u ^= 0x03;
    >


    In general, x <OP>= y works like x = x <OP> y. Find out what the
    operator ^ does, and go figure.
    Lars Enderin, Jul 29, 2009
    #2
    1. Advertising

  3. RVic

    Lew Guest

    RVic wrote:
    > > What  does the operator:

    >
    > > ^=

    >
    > > do?

    >
    > > I have it used in code I am working with as:

    >
    > >  byte u = 0x00;
    > >     for(int i = 0; i < msg.length(); i++) {
    > >       // ASSUMES: ASCII
    > >      u  ^= (byte)msg.charAt(i);
    > >     }
    > >     u ^= 0x03;

    >


    Eric Sosman wrote:
    >      ^= is to ^ as += is to + .  I pronounce it "XOR-equals,"
    > just as I pronounce += as "plus-equals."
    >


    RVic - you will find these links extremely useful:

    <http://java.sun.com/docs/books/tutorial/>
    <http://java.sun.com/docs/books/jls/third_edition/html/
    expressions.html#15.22>
    <http://java.sun.com/docs/books/jls/third_edition/html/
    expressions.html#15.26.2>

    --
    Lew
    Lew, Jul 29, 2009
    #3
  4. RVic

    Roedy Green Guest

    On Wed, 29 Jul 2009 08:14:43 -0700 (PDT), RVic <>
    wrote, quoted or indirectly quoted someone who said :

    >What does the operator:
    >
    >^=


    see http://mindprod.com/jgloss/xor.html

    x ^= y ;
    is just shorthand for
    x = x ^ y;
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    The USA and Iraq are as mismatched combatants as Mike Tyson and a bag lady. Americans make themselves look ridiculous when they justify invading and occupying Iraq in self defence.
    Roedy Green, Jul 29, 2009
    #4
  5. RVic

    Tom Anderson Guest

    On Wed, 29 Jul 2009, Lars Enderin wrote:

    > RVic wrote:
    >> What does the operator:
    >>
    >> ^=
    >>
    >> do?
    >>
    >> I have it used in code I am working with as:
    >>
    >> byte u = 0x00;
    >> for(int i = 0; i < msg.length(); i++) {
    >> // ASSUMES: ASCII
    >> u ^= (byte)msg.charAt(i);
    >> }
    >> u ^= 0x03;
    >>

    >
    > In general, x <OP>= y works like x = x <OP> y. Find out what the operator ^
    > does, and go figure.


    Great, now i know what == does!

    Bit confused about != though.

    :)

    tom

    --
    inspired by forty-rod whiskey
    Tom Anderson, Jul 29, 2009
    #5
  6. RVic

    Lars Enderin Guest

    Tom Anderson wrote:
    > On Wed, 29 Jul 2009, Lars Enderin wrote:
    >
    >> RVic wrote:
    >>> What does the operator:
    >>>
    >>> ^=
    >>>
    >>> do?
    >>>
    >>> I have it used in code I am working with as:
    >>>
    >>> byte u = 0x00;
    >>> for(int i = 0; i < msg.length(); i++) {
    >>> // ASSUMES: ASCII
    >>> u ^= (byte)msg.charAt(i);
    >>> }
    >>> u ^= 0x03;
    >>>

    >>
    >> In general, x <OP>= y works like x = x <OP> y. Find out what the
    >> operator ^ does, and go figure.

    >
    > Great, now i know what == does!
    >
    > Bit confused about != though.
    >

    Cute. Note that I wrote "in general". Perhaps I should have written
    "generally" or "usually". Anyway, the "=" is the assignment operator
    , of course. I
    started out with FORTRAN, and graduated to Simula, which uses ":=", and
    then I started programming in C, etc...
    Lars Enderin, Jul 29, 2009
    #6
  7. RVic

    Tom Anderson Guest

    On Wed, 29 Jul 2009, Lars Enderin wrote:

    > Tom Anderson wrote:
    >> On Wed, 29 Jul 2009, Lars Enderin wrote:
    >>
    >>> RVic wrote:
    >>>> What does the operator:
    >>>>
    >>>> ^=
    >>>>
    >>>> do?
    >>>>
    >>>> I have it used in code I am working with as:
    >>>>
    >>>> byte u = 0x00;
    >>>> for(int i = 0; i < msg.length(); i++) {
    >>>> // ASSUMES: ASCII
    >>>> u ^= (byte)msg.charAt(i);
    >>>> }
    >>>> u ^= 0x03;
    >>>>
    >>>
    >>> In general, x <OP>= y works like x = x <OP> y. Find out what the operator
    >>> ^ does, and go figure.

    >>
    >> Great, now i know what == does!
    >>
    >> Bit confused about != though.
    >>

    > Cute. Note that I wrote "in general".


    Insufficient to prevent jokes!

    > Perhaps I should have written
    > "generally" or "usually". Anyway, the "=" is the assignment operator
    > , of course. I started out with FORTRAN, and graduated to Simula, which uses
    > ":=", and then I started programming in C, etc...


    Ah, := in java would be the second part of the ternary assignment operator ...

    tom

    --
    No man ever steps in the same river twice, for it's not the same river
    and he's not the same man. -- Heraclitus
    Tom Anderson, Jul 31, 2009
    #7
  8. RVic

    Roedy Green Guest

    On Wed, 29 Jul 2009 19:39:30 +0100, Tom Anderson
    <> wrote, quoted or indirectly quoted someone who
    said :

    >Bit confused about != though.


    I would have preferred <>

    I used it, unthinkingly the other day, and puzzled that javac did not
    like it. A Pascal flashback.

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    The USA and Iraq are as mismatched combatants as Mike Tyson and a bag lady. Americans make themselves look ridiculous when they justify invading and occupying Iraq in self defence.
    Roedy Green, Jul 31, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page