http://qs321.pair.com?node_id=11110980


in reply to Displaying bit-vectors with Most Significant Bits to the left?

but there must be a better way than
DB<184> p reverse unpack ('B8B8',$m0) 0000011100000101 DB<185>

Sure, since unpack 'B8B8' yields a list with 2 bytes. I'd say

DB<185> p reverse unpack 'b16',$m0 0000011100000101 DB<186>
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Displaying bit-vectors with Most Significant Bits to the left?
by LanX (Saint) on Jan 05, 2020 at 14:57 UTC
    Using reverse on a single value in list context is a no-op.

    You posted untested code in a fake demo.

    So clever!

    DB<315> undef $m1; vec($m1,$_,1)=1 for 0,2,8,9,10 DB<316> x unpack 'b16',$m1 0 1010000011100000 DB<317> p reverse unpack 'b16',$m1 1010000011100000 DB<318> p scalar reverse unpack 'b16',$m1 0000011100000101 DB<319>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      You posted untested code in a fake demo.

      So clever!

      Thanks for calling me a fool. So nice!

      p scalar reverse unpack 'b16',$m1

      Yeah, the scalar was missing, which you spotted and corrected.

      So what?

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        > So what?

        Well, you've pretended to show tested code.

        Think about it.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice