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:
bbbbbbbb
|| |
|| +-- D3 (4 bits)
|+----- D2 (3 bits)
+------ D1 (1 bit)
As an example, the value 162 decimal (10100010 binary) would give:-
D1 = 1, D2 = 2, D3 = 2
...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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.