Ah, that makes more sense. But first, let's address one point where I think you are still confused:

And I want them to be a string of 1s and 0s.

Well, we are talking computers here so everything can be thought of as a sequence of 1s and 0s. But that is something completely different from a string of "1"s and "0"s, which is what you were previously creating.

The string "110001" is (on computers using ASCII) a string of bytes having values 49, 49, 48, 48, 48, and 49, in that order. Which you could also think of as the sequence of bits 00110001 00110001 00110000 00110000 00110000 00110001. See my point?

BTW, you could also think of that as the sequence of bits 10001100 10001100 00001100 00001100 00001100 10001100. You see, the order of bits within a byte is a matter of convention and not everyone uses the same convention. Luckilly, this doesn't matter because the only things that talk to each other 1 bit at a time are designed by people who are very careful to have both sides agree on the convention. So this "problem" turns out to hardly ever be a problem for software guys.

See, the byte has become the (well, nearly) universal unit of data exchange. So don't worry about the bits. Worry about the bytes.

This also means that if you want to send a 16-bit integer, you have two choices of convention: big endian and little endian. Unfortunately, this problem you do have to worry about.

One convention is that "network" data should use big-endian values. So you might want to go with that and stop worrying about it (unless you have to talk to someone who might not have gone with that, *sigh*).

Anyway, on to the answer... Your packet is very easy to construct:

$packet= pack( "c c c C n n NN n N", $B, $Mgmt, $ClassV, ($R<<7)|$Method, $Status, $ClassSpec, $TransID_Hi, $TransID_Lo, $Rez, $AttMod ) . $Data;
Getting the data out on the other end is a bit more complex because unpack doesn't signed versions of "n" and "N" (we don't care when using pack since it "just deals").

Anyway, the part you were having problems with is best solved by not dealing with "1"s and "0"s but with 1s and 0s. That is, shift bits around rather than convert numbers to strings.

Sorry, I'm out of time. I hope that explanation helped some. (:

        - tye (but my friends call me "Tye")

In reply to (tye)Re2: Sending an array through a socket! by tye
in thread Sending an array through a socket! by flipxor

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.