# XOR operator?

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

1. ### Daniel CarreraGuest

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
Mathematics Dept. | "To understand recursion, you must first
UMD, College Park | understand recursion".

Daniel Carrera, Oct 28, 2003

2. ### gabriele renziGuest

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

3. ### Jim FreezeGuest

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
4. ### Daniel CarreraGuest

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
Mathematics Dept. | "To understand recursion, you must first
UMD, College Park | understand recursion".

Daniel Carrera, Oct 28, 2003
5. ### Dave ThomasGuest

Dave Thomas, Oct 28, 2003
6. ### Josef 'Jupp' SchugtGuest

* 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