Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: pack/unpack 6 bit fields.

by etcshadow (Priest)
on Aug 18, 2004 at 05:01 UTC ( [id://383856]=note: print w/replies, xml ) Need Help??


in reply to pack/unpack 6 bit fields.

There's also vec (perldoc -f vec). For example:
# to turn your $str into an array @array = map { vec($str, $_*6, 6) } 0..15; # to turn an array of 6-bit items into a packed string vec($str, $_*6, 6) = $array[$_] for 0..$#array; # or simply to access the $i-th item in the $str, directly: $read_item = vec($str, $i*6, 6) = $write_item; # vec is an lvalue!
Enjoy.
------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re^2: pack/unpack 6-bit fields.(!vec)
by tye (Sage) on Aug 18, 2004 at 05:33 UTC

    My first guess is that you didn't try this code. For me, vec only allows field sizes that are powers of 2 (and this restriction is still in 5.8's vec docs -- the latest PM currently links to).

    Illegal number of bits in vec at ...

    - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2025-06-13 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.