Bitwise Operations On Large Strings In PHP Bitwise Operations On Large Strings In PHP php php

Bitwise Operations On Large Strings In PHP


Storing the values in strings is really the right way to go.

But instead of storing 1's and 0's, just store 8 bits in every byte. It will still be easy to extract parts of the integer from your string. You do need to manually do all operations such as shifting.


Clearly there is no way to use the native data structure that represents ints given your environment and so you have to use a data structure on top. This will mean of course that you will not be able to apply your example given ... 0xFFFFFFFF >> 4 but you could use mystruct(0xFFFFFFFF) >> 4 (mystruct being the data structure defined by you).

If this sounds like a plan let me know and maybe I can help you with the rest of the solution.


You could use bcmath. It has proven itself very good and goes with PHP since 4.0.4