Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Displaying bit-vectors with Most Significant Bits to the left?

by shmem (Chancellor)
on Jan 05, 2020 at 14:31 UTC ( #11110980=note: print w/replies, xml ) Need Help??


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 (Archbishop) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11110980]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2020-05-29 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (169 votes). Check out past polls.

    Notices?