in reply to Re^2: Understanding Shift Operators
in thread Understanding Shift Operators

What other way is there to look at it?
Another way to look at the left-shift operation is a mulitiply-by-power-of-2 operation. $num << $power is the same as $num * 2**$power:
use strict; use warnings; foo(1, 2); foo(1, 3); foo(5, 2); foo(7, 3); sub foo { my ($n, $p) = @_; print "$n << $p = ", $n << $p , "\n"; print "$n * 2**$p = ", $n * 2**$p, "\n\n"; } __END__ 1 << 2 = 4 1 * 2**2 = 4 1 << 3 = 8 1 * 2**3 = 8 5 << 2 = 20 5 * 2**2 = 20 7 << 3 = 56 7 * 2**3 = 56

Replies are listed 'Best First'.
Re^4: Understanding Shift Operators
by spickles (Scribe) on Apr 07, 2010 at 00:27 UTC

    Toolic -

    That's cool - thanks.