Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Bit operations for beginners

by liz (Monsignor)
on Aug 08, 2003 at 15:16 UTC ( [id://282213]=note: print w/replies, xml ) Need Help??


in reply to Bit operations for beginners

I think the truth table for "The ^ operator" is wrong. I think it should be:

Bit 0Bit 1Bit 0 ^ Bit 1
000
011
101
110

Also: "&&" works by evaluating the right operand, and if and only if that returns a true value the left operand is evaluated and that result is returned. "||" works similar, but only evaluates the left operand if the right operand was false.

This is incorrect. Perl always works from left to right. See:

$a = 0; $b = 0; $c = $a++ && $b++; # only $a++ is evaluated print "a = $a, b = $b\n"; # prints "a = 1, b = 0"
And:
$a = 0; $b = 0; $c = ++$a || ++$b; # only ++$a is evaluated print "a = $a, b = $b\n"; # prints "a = 1, b = 0"
Otherwise I think this can go to Tutorials as well...

Liz

Replies are listed 'Best First'.
Re: Re: Bit operations for beginners
by Cine (Friar) on Aug 09, 2003 at 10:09 UTC
    Ups :( I even proofread it 5-6 times... Remember, always have someone else proofread it too...

    T I M T O W T D I

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://282213]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-16 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found