Binary formats sometimes use all of the bits they are given - when I was working with MIDI, I came across this a lot. (If you have an int, you might as well use all 32 of those guys.)
For example, 16bit color is often 5bits red, 6bits green, and 5bits blue. That means it's all packed into rrrrrggggggbbbbb,
where each letter represents a bit. I wrote some Python to write the C code for me.
The Python script takes a string like "00rrr000" and outputs C code with the appropriate shifts and masks.
I find "00rrr000" to be a lot clearer than '(packed & 0x3f)>>3' .
The source is on GitHub here (it's not pretty yet) under the GPLv3.