binary value in one string byte

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drugcoder
Forum Newbie
Posts: 2
Joined: Fri Mar 04, 2005 1:08 pm

binary value in one string byte

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

drugcoder
Forum Newbie
Posts: 2
Joined: Fri Mar 04, 2005 1:08 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

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

Code: Select all

pack
Post Reply