INT最大尺寸为32位系统 [英] INT max size for 32bit system

查看:211
本文介绍了INT最大尺寸为32位系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我们正在谈论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位。只是默认输出函数解释为有符号整数。如果要显示值raw,请使用:

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.

这篇关于INT最大尺寸为32位系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆