Page 1 of 1

binary value in one string byte

Posted: Fri Mar 04, 2005 1:11 pm
by drugcoder
I am working on some socket communications using PHP, and am having a small problem. The server is requiring the packet size be listed in binary using the first four bytes.

I don't know what I'm doing wrong but I can't seem to store a binary number in these four bytes.

Does anyone have any suggestions?

Posted: Fri Mar 04, 2005 1:18 pm
by feyd

Posted: Fri Mar 04, 2005 1:24 pm
by drugcoder
So would you suggest something like

$PckLen = pack('a4',78);

to show a packet length of 78 bytes, using a null padded 4 byte string?

Posted: Fri Mar 04, 2005 1:34 pm
by feyd

Code: Select all

$num = 1885430635;
echo pack('N',$num);
outputs

Code: Select all

pack