develooper Front page | perl.perl5.porters | Postings from September 2005

[perl #969] shifting of bitvecs considered broken

From:
Steve Peters via RT
Date:
September 27, 2005 19:50
Subject:
[perl #969] shifting of bitvecs considered broken
Message ID:
rt-3.0.11-969-121712.4.84921393289916@perl.org
> [stmpeters - Wed Jul 20 05:56:11 2005]:
> 
> > Resubmitting a bug report of mine back from February;
> > this time through the proper channel (perlbug, not p5p).
> > 
> > [paste]
> > 
> > While editing my Damn Book I re-remembered that couple of months back
> > I ran into an anomaly in the handling of bitvectors.
> > 
> > Fiction: you have a bitvector which you want to shift.
> > 
> > The current (5.005_03-MT5) fact:
> > 
> > perl -wle '$b = ""; vec($b, 0, 1) = 1;print unpack("b*",
> > $b);$b<<=1;print unpack("b*", $b)'
> > 10000000
> > 00001100
> > 
> > Huh?  Adding -w tells more, as usual:
> > Argument "^A" isn't numeric in left_shift at -e line 1.
> > 
> > So left_shift assumes that the argument to shift is a number, but "^A"
> > isn't, so it gets converted to string zero "0" (48, 0x30, 0b0000110).
> > 
> > I consider this behaviour to be rather broken.  I think
> > 
> >         $b <<= 1
> > 
> > should shift the whole bitvector left by one position and
> > 
> >         vec($b, 2, 8) >>= 2
> > 
> > should shift the bits 16..23 right by two positions (of course not
> > leaking into bits 8..15).
> > 
> 
> Just so we're clear, and to add a proper TODO test case, what would you
> consider the proper output to be?
> 

This thread sort of went off on a tangent.  What should the expected
results be?



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About