Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: 5x6-bit values into/out of a 32-bit word

by ikegami (Pope)
on Mar 18, 2007 at 01:30 UTC ( #605329=note: print w/ replies, xml ) Need Help??

in reply to 5x6-bit values into/out of a 32-bit word

Assuming the following bit layout:

0055 5555 4444 4433 3333 2222 2211 1111
One way:
# Get individual num: $num = ($aggregate >> ($i*6)) & 0b111111; # Set individual num: $aggregate = ($aggregate & ~(0x3F << ($i*6))) | ($num << ($i*6));

Update: Added missing ~.
Update: Thelonius's newer post shows how to use this method to get/set all the nums at once.

Comment on Re: 5x6-bit values into/out of a 32-bit word
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2016-02-13 09:47 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (423 votes), past polls