Very whacky results Bitshifting in PHP. PLEASE help!
Posted: Sat Oct 22, 2005 12:16 pm
Hi,
I'm trying to do some bit comparison in PHP. The code used is a ^= b which is suppose to extract bits which are in either A or B but not in both A and B.
This seems to work perfectly for numbers that match in binary length, but numbers that are shorter or longer return very strange results. See below.
11001001001100101101100101001010=3375552842 (original first number a A)
1111010010101100101110000000000 =2052480000 (original second number B)
1001100100110110111101010110110 =-1285257910 (PHP Result, negative?)
10110011011001001000010101001010=3009709386 (VB.net Result)
10110011011001001000010101001010=3009709386 (Done manually by inserting a leading 0 in front of binary b)
So what is PHP actually doing here? I've spent half the night last night and still cant figure it out!
Thanks a bunch!
DRT
I'm trying to do some bit comparison in PHP. The code used is a ^= b which is suppose to extract bits which are in either A or B but not in both A and B.
This seems to work perfectly for numbers that match in binary length, but numbers that are shorter or longer return very strange results. See below.
11001001001100101101100101001010=3375552842 (original first number a A)
1111010010101100101110000000000 =2052480000 (original second number B)
1001100100110110111101010110110 =-1285257910 (PHP Result, negative?)
10110011011001001000010101001010=3009709386 (VB.net Result)
10110011011001001000010101001010=3009709386 (Done manually by inserting a leading 0 in front of binary b)
So what is PHP actually doing here? I've spent half the night last night and still cant figure it out!
Thanks a bunch!
DRT