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:
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").$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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |