关于php中intval在32和64位的有关问题

WBOY
Release: 2016-06-13 11:18:31
Original
1067 people have browsed it

关于php中intval在32和64位的问题

php的int行在32位的系统上是4Byte,在64位上是8Byte,导致在超过4Byte的整数,在32和64返回的结果不同,现在写一个统一的函数,统一用32位的算法


function intval32($num) { $num = $num & 0xffffffff;//消掉高32位   $p = $num>>31; //取第一位 判断是正数还是负数 if($p==1) { //负数 $num = $num-1; $num = ~$num; //取反 会当成64位取反,算出来的数就去了,所以取反之后 要消掉 高32位 $num = $num & 0xffffffff; return $num * -1; } else { return $num; } } 
Copy after login



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!