http://qs1969.pair.com?node_id=282213


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