Pack / unpack a 64-bit int on 64-bit architecture in PHP

前端 未结 4 1284
梦谈多话
梦谈多话 2020-12-19 14:30

Why do I get the following output on an x64 architecture?

$ php -r \'echo pow(2, 33) . \"\\n\";print_r(unpack(\"Ivalue\", pack(\"I\", pow(2, 33))));\'
858993         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 15:27

    Because pack takes the second parameter as a string and converts it to a 32-bit int. The only relief is unsigned as far as bit-size limitations. Looking at the source code I see a 64-bit version coming soon from Perl that uses 'Q' to force 64-bit machine endian.

提交回复
热议问题