Problem with ^ oprator

2003-04-04 Thread Rado Petrik
Hi, 

I have two number 

$a=6;  #binary - 0110
$b=10; # 1010

I need work this operation  a OR b 
0110  - 6 
OR  1010  - 10
-
1110  - 14  this is true;

buy when I use this operator ^ in perl 

$a^$b  then output is 12

0110  - 6 
OR  1010  - 10
-
1100  - 12 false; 
 
Why ? How I make true output? 
Thanks. 
 
 







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem with ^ oprator

2003-04-04 Thread Jenda Krynicky
From: Rado Petrik [EMAIL PROTECTED]
 I have two number 
 
 $a=6;  #binary - 0110
 $b=10; # 1010
 
 I need work this operation  a OR b 
 0110  - 6 
 OR  1010  - 10
 -
 1110  - 14  this is true;
 
 buy when I use this operator ^ in perl 
 
 $a^$b  then output is 12
 
 0110  - 6 
 OR  1010  - 10
 -
 1100  - 12 false; 
 
 Why ?

^ is XOR. That is exclisive OR ... the resul with have 1 only on 
those places where either one or the other argument had 1, but not 
both.

0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0

What you want is

$a | $b

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem with ^ oprator

2003-04-04 Thread Brett W. McCoy
On 4 Apr 2003, Rado Petrik wrote:

 I have two number

 $a=6;  #binary - 0110
 $b=10; # 1010

 I need work this operation  a OR b
 0110  - 6
 OR  1010  - 10
 -
 1110  - 14  this is true;

 buy when I use this operator ^ in perl

 $a^$b  then output is 12

 0110  - 6
 OR  1010  - 10
 -
 1100  - 12 false;

^ is XOR, not OR.  You want to use | for bitwise OR.

$ perl -e 'print 6 | 10'
14

-- Brett


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]