Page 1 of 1

xor function

Posted: Tue Jul 02, 2002 10:38 am
by probkid
Hi,
I'm having some problem using the function "xor" to get xor value of 2 bit strings. The strings that i am using are:
1001100010111111010010000000010010110001110110100100110001101001
and
1000001100111111011010110101000100100001101001111100110010100110
and I am getting the wrong result as
1001100010111111010010000000010010110001110110100100110001101001
whereas it should be
0001101110000000001000110101010110010000011111011000000011001111

Any ideas as to why this happens and what is the way to work around this?

Any help would be greatly appreciated.

Thanks.

Posted: Tue Jul 02, 2002 10:44 am
by RandomEngy
A simple workaround would just involve looping through the string, adding a '1' to the string if the bits are (0,1) or (1,0) and a '0' if the bits are (0,0) or (1,1). I'm sure you can code something like that.

xor function

Posted: Tue Jul 02, 2002 10:53 am
by probkid
You're right. I thought of writing a function but was just wondering why such a simple function was giving incorrect results, in php and if there was a readymade workaround!!
But, I guess I'll have to write my own function now.
Thanks!!

Posted: Tue Jul 02, 2002 11:09 am
by llimllib
Looking through the manual, I'm pretty sure that it happens because PHP will only work with 32-bit or less numbers accurately. you should check out the GMP Library Reference at http://www.php.net/manual/en/ref.gmp.php. This will allow you arbitrary precision.[/url]