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:-bbbbbbbb || | || +-- D3 (4 bits) |+----- D2 (3 bits) +------ D1 (1 bit)
...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.D1 = 1, D2 = 2, D3 = 2
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extracting Bit Fields (Again)
by ikegami (Patriarch) on Oct 12, 2005 at 03:53 UTC | |
by Aristotle (Chancellor) on Oct 12, 2005 at 05:27 UTC | |
by ozboomer (Friar) on Oct 12, 2005 at 05:29 UTC | |
by ikegami (Patriarch) on Oct 12, 2005 at 14:17 UTC | |
by ozboomer (Friar) on Oct 13, 2005 at 10:20 UTC | |
by ikegami (Patriarch) on Oct 13, 2005 at 13:17 UTC | |
Re: Extracting Bit Fields (Again)
by BrowserUk (Patriarch) on Oct 12, 2005 at 04:26 UTC | |
by oyster2011 (Initiate) on Dec 22, 2011 at 05:23 UTC | |
by BrowserUk (Patriarch) on Dec 22, 2011 at 08:35 UTC | |
by oyster2011 (Initiate) on Jan 02, 2012 at 06:22 UTC | |
by BrowserUk (Patriarch) on Jan 02, 2012 at 07:10 UTC | |
| |
Re: Extracting Bit Fields (Again)
by GrandFather (Saint) on Oct 12, 2005 at 03:42 UTC | |
Re: Extracting Bit Fields (Again)
by pg (Canon) on Oct 12, 2005 at 03:58 UTC | |
Re: Extracting Bit Fields (Again)
by ysth (Canon) on Oct 12, 2005 at 08:45 UTC | |
by BrowserUk (Patriarch) on Oct 12, 2005 at 09:32 UTC | |
by ysth (Canon) on Oct 12, 2005 at 22:38 UTC |
Back to
Seekers of Perl Wisdom