in reply to Extracting Bit Fields (Again)
There are no rotate readily available in Perl, but Perl does have shift operators (<< and >>) and that's all you need:
$D1 = ($num >> 7) & 0x01; # 1 bit starting at bit 7. $D2 = ($num >> 4) & 0x07; # 3 bits starting at bit 4. $D3 = ($num >> 0) & 0x0F; # 4 bits starting at bit 0.
The above is much easier than using unpack because unpack('b', ...) returns a string representation of the number. You can work around it as follows (for fields no bigger than 8 bits):
@D = map { unpack('C', pack('b*', $_)) } unpack('b1b3b4', 162);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extracting Bit Fields (Again)
by Aristotle (Chancellor) on Oct 12, 2005 at 05:27 UTC | |
|
Re^2: Extracting Bit Fields (Again)
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 |