shelob101 has asked for the wisdom of the Perl Monks concerning the following question:
Well, I understand binary math and what I *want* the final 16 bit thingy to look like. I'm still fuzzzy on how to use pack() to achieve this. If, for example:| Style MSB | Style LSB | |15 9 | 4 1 0| ----------------------------------------- | reserved |Structure|App wid|Pos| So, reading from right to left, bits 0 and 1 = Posture (poss values 0-3) bits 2-4 = Appearance Width (0-7) bits 5-9 = Structure (0-31) bits 10-15 = Reserved (locked to value of 0)
I've triedposture=2 (10) app_width=5 (101) structure=6 (00110) then the bits should look like: 000000 00110 101 10 or, without the spaces: 0000000011010110
but that doesn't work. Should I be using b or B as a template code? Should I be using regular integer values like 2, 5 and 6 or should I be packing those into some other bitstring first? Worse yet, I'm at a loss on how to debug this thing and see an understandable representation of what's really getting put into $sw. I'd love to see a series of 0's and 1's which represent the individual bits of this 16 bit word. Then I could be sure what I'm putting into the structure before writing it to disk. Any help would be greatly appreciated.my $style_word=pack(b2 b3 b5 b6),$pos,$aw,$stru,0;
Shelob
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using pack() to build a 16 bit word
by Roy Johnson (Monsignor) on May 11, 2004 at 21:12 UTC | |
by fizbin (Chaplain) on May 12, 2004 at 12:33 UTC | |
|
Re: using pack() to build a 16 bit word
by Ven'Tatsu (Deacon) on May 11, 2004 at 19:07 UTC | |
|
Re: using pack() to build a 16 bit word
by jmcnamara (Monsignor) on May 11, 2004 at 20:21 UTC |