Numeric string (custom size) & # 8594; Multiple integers

I have a problem because there is BIGINT data (64-bit integers) in my database, but the PHP version that I am running is only 32-bit.

So when I pull the value out of the table, I get a numeric string representing a 64-bit integer in base 10. What I would ideally want to do is use a 64-bit integer as a bitmask. So I need to go to two 32-bit integers (one of which is the upper part and one lower part) or a numeric string in base 2.

The problem is that I cannot just multiply this because my PHP is only 32-bit. I am stuck?

+3
source share
3 answers

You can use MySQL bit shift operators to split a 64-bit integer into two 32-bit integers. So you can choose:

select (myBigIntField & 0xffffffff) as lowerHalf,
       (myBigIntField >> 32) as upperHalf
+6
source

To handle integers of arbitrary size, you have two options in PHP: GMP and BC Math Methods .

I believe GMP is more efficient using some user resources, while BC uses strings directly.

If you do not process too many (thousands or more) numbers at a time, you can use BC directly.

+1
source

:

  • BCMath GMP PHP. .
  • 64
  • Write the bignum implementation yourself (more work :-))
+1
source

Source: https://habr.com/ru/post/1720251/


All Articles