in reply to using pack() to build a 16 bit word
You can also throw a bitwise and in there to make sure values can't overflow their bit fieldspack('n', $stru << 5 | $aw << 2 | $pos)
I'm guessing it's big-endian, if not use v in pack instead of npack('n', ($stru & 31) << 5 | ($aw & 7) << (2 & 3) | $pos)
|
|---|