问题描述
假设我们谈论的是 32 位系统.
Lets assume we are talking about 32bit system.
PHP 不支持无符号 INT.这意味着 INT 值应介于 -2,147,483,648 和 2,147,483,647 之间.而 INT 需要 4 个字节来存储一个 32 位长度的值.
PHP doesn't support unsigned INT. It means that INT value should be between -2,147,483,648 and 2,147,483,647 values. And INT takes 4 bytes to store a value which are 32 bits length.
这是否意味着我只有 31 位值和 1 位符号?或者我可以使用整个 32 位来存储一个值?
So does it mean that I have only 31 bits for value and 1 bit for sign? Or I can use whole 32 bits to store a value?
推荐答案
您正在使用整个 32 位.只是默认输出函数将解释为有符号整数.如果要显示值原始",请使用:
You are using the whole 32 bits. It's just that the default output functions interpret it as signed integer. If you want to display the value "raw" use:
printf("%u", -1); // %u for unsigned
由于 PHP 处理内部有符号的整数,因此您只能使用位算术,但不能使用加法/乘法等 - 如果您希望它们表现得像无符号整数.
Since PHP handles the integers signed internally however, you can only use bit arithmetics, but not addition/multiplication etc. with them - if you expect them to behave like unsigned ints.
这篇关于32 位系统的 INT 最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!