Web Hosting Talk







View Full Version : PHP and binary numbers


Gyrbo
03-10-2003, 03:31 PM
I'm trying to make an ssl server in php and I'm stuck at the point where I have to send the size of a packet to the client. According to the SSL specs, this should be in big endian order.
Converting this number to binary form was easy using pack(), but there is one slight problem.
According to what I caputured with a network sniffer, the number 76 is represented by 0x804c and the pack() function gives 0x004c.
I've tried using & and | with various parameters but I couldn't get the number right.

If somebody can help me with this, I would be really happy. This is the first obsticles on the long road to a fully working SSL server.

jonasf
03-12-2003, 06:40 PM
0x004c is the same as 0x804c just that the 16th bit is set. If you want to set it, just do var = 0x004 | 0x800 should work. Didn't try it though and i am not to proficient with binaries

jonasf
03-12-2003, 11:36 PM
If you just want to unset it, use xor:
var = 0x804 ^ 0x800

Gyrbo
03-13-2003, 02:44 PM
Thanks all, I will try this.