C
Chris
Hi
I'm attempting to write a client for an existing p2p network.
The protocol defines that ints are packed into 4 bytes for transfer.
// Creating the byte vector using the following is fine:
for(int i=3; i>=0; i--) {
vecBuff.push_back(value&0xff);
value/=256;
}
// but reading out an int value from the array using
value = (int)data[0] + (int)data[1]*256 + (int)data[2]*65536 +
(int)data[3]*16777216;
Gives varying results. Often correct but sometimes the results is a
negative number, which i don't believe to be correct.
Is my method above for unpacking the int correct?
Thanks loads in advance.
Chris
I'm attempting to write a client for an existing p2p network.
The protocol defines that ints are packed into 4 bytes for transfer.
// Creating the byte vector using the following is fine:
for(int i=3; i>=0; i--) {
vecBuff.push_back(value&0xff);
value/=256;
}
// but reading out an int value from the array using
value = (int)data[0] + (int)data[1]*256 + (int)data[2]*65536 +
(int)data[3]*16777216;
Gives varying results. Often correct but sometimes the results is a
negative number, which i don't believe to be correct.
Is my method above for unpacking the int correct?
Thanks loads in advance.
Chris