Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://605329]
[LanX]: do you know the story of the triangle player?
[choroba]: Oh, the Czech one playing the German composition?
[choroba]: BTW, the elections are over. We already have the final results.
[choroba]: I should probably apply for a job somewhere abroad.
[LanX]: nope this one One day the triangle player of an orchestra gets very ill and goes to the hospital.. ..

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-10-21 19:34 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (270 votes). Check out past polls.