Home > Backend Development > PHP Tutorial > PHP什么是整数溢出?

PHP什么是整数溢出?

PHPz
Release: 2020-09-05 10:28:11
Original
2950 people have browsed it

PHP什么是整数溢出?

进制和整型

整型值可以使用十进制,十六进制,八进制或二进制表示,前面可以加上可选的符号(- 或者 +)。

注意:要使用八进制表达,数字前必须加上 0。要使用十六进制表达,数字前必须加上 0x。要使用二进制表达,数字前必须加上 0b。

<?php
$a = 1234; // 十进制数
$b = -123; // 负数
$c = 0123; // 八进制数 (等于十进制 83)
$d = 0x1A; // 十六进制数 (等于十进制 26)
?>
Copy after login

整数溢出

如果给定的一个数超出了 integer 的范围,将会被解释为 float。同样如果执行的运算结果超出了 integer 范围,也会返回 float。

对于32位的操作系统,最大的整型是2147483647,即2的31次方,最小为-2的31次方。本次实验环境:PHP 7.2,Ubuntu 14.04。

<?php

$a = 123445566;
$b = 9223372036854775807;
$c = 9223372036854775808;
$d = 50000000000000 * 1000000;

var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
Copy after login

执行得到结果为:

int(123445566)
int(9223372036854775807)
float(9.2233720368548E+18)
float(5.0E+19)
Copy after login

更多相关知识,请访问 PHP中文网!!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template