Hello, I have to pack a complicated message into a 16-bit word that is defined like so:

Part 1: Error State (Least Significant Byte)
Part 2: Mode/Status/Additional Status

Part 1 Error State is defined like so:
Bit 0: Error type A (Least Significant Bit)
Bit 1: Error type B
Bit 2: Error type C
Bit 3: Error type D
Bit 4: Error type E
Bit 5: Error type F
Bit 6: Error type G
Bit 7: Error type H (Most significant Bit)

Part 2: Mode/Status Additional Status is defined like so:
Mode: The mode is contained in the least significant 4 bits of the most significant byte. Mode numbers go 0 - 11.
Status:
Bit 12: Status Type A
Bit 13: Status Type B
Bit 14: Status Type C
Additional Status:
Bit 15: Reset on/off

I can't seem to get the pack() command right. I want to pack:
Error type E, Mode 7, Status Type B, Additional Status ON

my $msg = pack("n", pack("C", 0, 0, 0, 0, 1, 0, 0, 0), #error state pack("C", 7, 0, 1, 0, 1) );

Perl doc, http://perldoc.perl.org/functions/pack.html, does not say about little/big endian when it comes to packing chars.


In reply to Pack()-ing a Message by rem45acp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.