By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

storing a bit in a byte

P: 1
I'm writing a Gnutella client in PHP and in order to create routing tables I need to store a bit inside a byte and then send those bytes across a file stream. However, I'm not sure how to convert what appears to be an integer byte to a bit. After I convert it though I think I would run it through the pack() function.

$byte = pack('c',0);
$byte = pack('c',1);

From the Limewire FAQ:
In LimeWire's source code, a QRP table is represented by a Java BitSet object. There are 65536 bits. Bits set to 0 block searches, while those set to 1 let searches through. Gnutella programs could transmit QRP tables simply by sending these 65536 bits across the wire. Unfortunately, the method modern Gnutella uses is much more complex.

To begin, a Gnutella program prepares an array of patch data that is 65536 bytes long. There is one byte of patch data for each bit in the table. A 0 byte in patch data indicates no change. It means the corresponding table bit has not changed since the last group of patch messages, or since the reset message at the start of the connection established a completely opaque table.

I'm testing this on mac (PPC) so I'm expecting endian issues and issues with PHP's lack of 32bit+ capability.
Oct 17 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.