Numeric String (arbitrary size) -> Multiple Integers
Question
I'm running into a problem because my database has BIGINT data (64-bit integers) but the version of PHP I'm running is only 32-bit.
So when I pull out value from a table I end up with a numeric string representing a 64-bit integer in base 10. What I would ideally like to do is use the 64-bit integer as a bitmask. So I need to go to either two 32-bit integers (one representing the upper part and one the lower part) or a numeric string in base 2.
Problem is I can't just multiply it out because my PHP is only 32-bit. Am I stuck?
Solution
You can use MySQL's bit shift operators to split the 64-bit integer into two 32-bit integers. So, you could select:
select (myBigIntField & 0xffffffff) as lowerHalf,
(myBigIntField >> 32) as upperHalf
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow