Hanamaki
Hanamaki

Reputation: 11

How to pack a 64bit integer with PHP32?

I want to use $_REQUEST to get a 64-bit integer, but it does not support 64-bit. (It will be turned to a float.) I need to pack this data and send to service. However it should be big endian byte order, so I can't use format f (float (machine dependent size and representation)) to pack it.

I tried to break it to four 16-bit integers, but I can't use <<,>>or & because it's a float.

How can I solve this problem?

Upvotes: 1

Views: 286

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798774

Use gmp_div_qr() with 256 or 65536 multiple times to break it up into 8- or 16-bit chunks, then convert those chunks into strings.

Upvotes: 1

Related Questions