Art Davis wrote:
> perldl> $a=sequence(5)
> perldl> p$a
> [0 1 2 3 4]
> perldl> $b=pdl(1)
> perldl> $c=$a->shiftleft($b,0);
> perldl> p$c
> [0 2 4 6 8]
> 
> Looks like the syntax is OK and it's being interpreted by perldl. Pete 
> said that the shift command works bitwise and I haven't invested the 
> mental energy to comprehend what that means yet.
> 

It just means that shiftleft works like the C << operator (or >> - I mix 
them up!).

Anyway, it is easy to see if you print out in binary, e.g.:


perldl> $a=pdl([0,1,2,4,8])

perldl> wcols "%2d  %10b", $a, $a
  0           0
  1           1
  2          10
  4         100
  8        1000

perldl> $b=pdl(1)

perldl> $c = $a->shiftleft($b, 0)

perldl> wcols "%2d  %2d %10b", $a, $c, $c
  0   0          0
  1   2         10
  2   4        100
  4   8       1000
  8  16      10000


(the last column is the binary representation in case %b is unfamiliar). 
So you see that what happens is that you shift the bit-pattern leftwise 
- adding zeros at the end. shiftright does the opposite and when it 
reaches zero it remains zero.

Hope that clears it up!

        Cheers, 
            Jarle.

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to