Professional Web Applications Themes

XOR operator? - Ruby

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"....

  1. #1

    Default XOR operator?

    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 Guest

  2. #2

    Default Re: XOR operator?

    On Wed, Oct 29, 2003 at 05:36:01AM +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?
    The xor operator in Ruby is ^ (just one). It serves as both bitwise
    and Boolean, depending on its arguments:

    irb(main):001:0> 2 ^ 1
    => 3
    irb(main):002:0> true ^ false
    => true
    irb(main):003:0> true ^ true
    => false

    -Mark
    Mark J. Reed Guest

  3. #3

    Default Re: XOR operator?

    il Wed, 29 Oct 2003 05:36:01 +0900, Daniel Carrera
    <dcarreramath.umd.edu> 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 Guest

  4. #4

    Default Re: XOR operator?

    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

    Lyle Johnson Guest

  5. #5

    Default Re: XOR operator?

    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 Guest

  6. #6

    Default Re: XOR operator?

    On Wed, Oct 29, 2003 at 05:36:01AM +0900, 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. I searched through PickAxe and
    > couldn't find a mention of xor.
    Neither Ruby in a Nutshell mentions one. However I made a quick tests and it
    seems it is safe to use ^ for integers.

    Dalibor

    --
    Dalibor Sramek [url]http://www.insula.cz/dali[/url] | In the eyes of cats,
    [email]dalibor.sramekinsula.cz[/email] | all things belong to cats.

    Dalibor Sramek Guest

  7. #7

    Default Re: XOR operator?

    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 Guest

  8. #8

    Default Re: XOR operator?


    On Oct 28, 2003, at 14:36, 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.
    >
    [url]http://www.rubycentral.com/book/ref_c_falseclass.html#FalseClass._up[/url]
    [url]http://www.rubycentral.com/book/ref_c_fixnum.html#Fixnum.Bitoperations[/url]

    etc


    Dave Thomas Guest

  9. #9

    Default Re: XOR operator?

    * 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 Guest

  10. #10

    Default Re: XOR operator?

    On Tue, Oct 28, 2003 at 11:21:33PM +0000, Josef 'Jupp' Schugt wrote:
    > 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)?
    AFAIK, Ruby got it from Perl, which got it from Fortran, only because
    C has no exponentiation operator and ^ was taken by XOR.

    -Mark
    Mark J. Reed Guest

Similar Threads

  1. operator
    By Gyger in forum PHP Development
    Replies: 3
    Last Post: August 18th, 07:18 AM
  2. operator |=
    By ··········· sylvain in forum PHP Development
    Replies: 7
    Last Post: September 22nd, 11:34 AM
  3. or operator
    By Paul Kraus in forum PERL Beginners
    Replies: 0
    Last Post: August 29th, 05:58 PM
  4. k operator in REGEX??
    By darkname in forum PERL Miscellaneous
    Replies: 6
    Last Post: July 7th, 09:18 AM
  5. BETWEEN OPERATOR
    By LPT in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 3rd, 05:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139