XOR operator?

Discussion in 'Ruby' started by Daniel Carrera, Oct 28, 2003.

  1. Hi all,

    I'm trying to figure out what the boolean "xor" operator is in Ruby. I
    thought it was "^^" but that doesn't work. I searched through PickAxe and
    couldn't find a mention of xor.

    Does Ruby have an xor?

    Cheers,
    --
    Daniel Carrera | OpenPGP KeyID: 9AF77A88
    PhD grad student. |
    Mathematics Dept. | "To understand recursion, you must first
    UMD, College Park | understand recursion".
    Daniel Carrera, Oct 28, 2003
    #1
    1. Advertising

  2. il Wed, 29 Oct 2003 05:36:01 +0900, Daniel Carrera
    <> ha scritto::

    >Hi all,
    >
    >I'm trying to figure out what the boolean "xor" operator is in Ruby. I
    >thought it was "^^" but that doesn't work. I searched through PickAxe and
    >couldn't find a mention of xor.



    it is just one ^
    >> 0b0000^0b0111

    => 7
    gabriele renzi, Oct 28, 2003
    #2
    1. Advertising

  3. Daniel Carrera

    Jim Freeze Guest

    On Wednesday, 29 October 2003 at 5:36:01 +0900, Daniel Carrera wrote:
    > Hi all,
    >
    > I'm trying to figure out what the boolean "xor" operator is in Ruby. I
    > thought it was "^^" but that doesn't work. I searched through PickAxe and
    > couldn't find a mention of xor.
    >
    > Does Ruby have an xor?


    irb(main):001:0> 1 ^ 0
    => 1
    irb(main):002:0> 1 ^ 1
    => 0
    irb(main):003:0> 0 ^ 0
    => 0
    irb(main):004:0> 0 ^ 1
    => 1


    --
    Jim Freeze
    ----------
    The Roman Rule
    The one who says it cannot be done should never interrupt the
    one who is doing it.
    Jim Freeze, Oct 28, 2003
    #3
  4. Thanks everyone. Yeah, ^ seems to work.



    On Tue, Oct 28, 2003 at 03:04:04PM -0600, Lyle Johnson wrote:
    > Daniel Carrera wrote:
    >
    > >I'm trying to figure out what the boolean "xor" operator is in Ruby. I
    > >thought it was "^^" but that doesn't work.

    >
    > It's just a single "^" character, e.g.
    >
    > six = 2 ^ 4
    >
    > Hope this helps,
    >
    > Lyle


    --
    Daniel Carrera | OpenPGP KeyID: 9AF77A88
    PhD grad student. |
    Mathematics Dept. | "To understand recursion, you must first
    UMD, College Park | understand recursion".
    Daniel Carrera, Oct 28, 2003
    #4
  5. Daniel Carrera

    Dave Thomas Guest

    Dave Thomas, Oct 28, 2003
    #5
  6. * Daniel Carrera; Wed, 29 Oct 2003 06:28:45 +0900

    > Thanks everyone. Yeah, ^ seems to work.

    [...as an XOR operator]

    One should add that the exponentiation operator is '**'.
    Matz, does that syntax mean that Ruby also has COBOL or FORTRAN
    heritage (I am not aware of anything else that would justify that
    assumption)?

    Josef 'Jupp' Schugt
    Josef 'Jupp' Schugt, Oct 28, 2003
    #6
    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.
Similar Threads
  1. Buck Turgidson

    XOR Boolean

    Buck Turgidson, Apr 5, 2004, in forum: Java
    Replies:
    9
    Views:
    9,097
    Kristoffel
    Apr 5, 2004
  2. cryptogirl

    How can you xor ArrayLists?

    cryptogirl, Feb 24, 2006, in forum: Java
    Replies:
    7
    Views:
    804
  3. Christopher Benson-Manica

    Why isn't there a logical XOR operator?

    Christopher Benson-Manica, Feb 3, 2004, in forum: C Programming
    Replies:
    80
    Views:
    3,355
    CBFalconer
    Feb 6, 2004
  4. Dr. Phillip M. Feldman

    missing 'xor' Boolean operator

    Dr. Phillip M. Feldman, Jul 14, 2009, in forum: Python
    Replies:
    71
    Views:
    2,119
    Terry Reedy
    Jul 27, 2009
  5. Pavel Smerk
    Replies:
    2
    Views:
    102
    Daniel Martin
    Aug 16, 2006
Loading...

Share This Page