Home  >  Article  >  php教程  >  将输入转换为32位无符号整数,若溢出,则只保留低32位

将输入转换为32位无符号整数,若溢出,则只保留低32位

PHP中文网
PHP中文网Original
2016-05-25 17:09:532181browse

将输入转换为32位无符号整数,若溢出,则只保留低32位

function uint32val($var) {
    if (is_string($var)) {
        if (PHP_INT_MAX > 2147483647) {
            $var = intval($var);
        } else {
            $var = floatval($var);
        }
    }
    if (!is_int($var)) {
        $var = intval($var);
    }
    if ((0 > $var) || ($var > 4294967295)) {
        $var &= 4294967295;
        if (0 > $var) {
            $var = sprintf('%u', $var);
        }
    }
    return $var;
}

                   

 以上就是将输入转换为32位无符号整数,若溢出,则只保留低32位的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
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