Extracting Bit Fields (Again)by ozboomer (Friar)
|on Oct 12, 2005 at 03:35 UTC||Need Help??|
ozboomer has asked for the wisdom of the Perl Monks concerning the following question:
I still can't get my head around this bit manipulation very well at the moment. Maybe its' just that I'm full of 'flu and I'm not seein' the obvious... Still, the current problem:
An 8-bit byte that has 3 bit-fields in it, thus:
As an example, the value 162 decimal (10100010 binary) would give:-
...but try as a I might, I just can't get the thing out. unpack(b1b3b4, $value) doesn't work, using vec() doesnt' help either.
I can logically "&" the value and get the bits selected out but I'd then need to do a 'rotate right' or something to get them into usable numbers.
Any pointers on how to get 'round this?