简体   繁体   English

sprintf%u给出错误结果

[英]sprintf %u gives wrong result

Simple script, PHP 5.3.13, Windows 8, x32 简单脚本,PHP 5.3.13,Windows 8,x32

<?php var_dump(sprintf('%u', -1380556906));

It gives me correct result 它给我正确的结果

string(10) "2914410390"

the same thing with PHP 5.4.11, Freebsd 9.1, x64 gives 与PHP 5.4.11,Freebsd 9.1,x64相同

string(20) "18446744072328994710"

Why? 为什么? How can I print signed int as unsigned int? 如何将带符号的int打印为无符号的int?

@Barmar has given the answer in the comments. @Barmar在评论中给出了答案。

You are experiencing an unsigned integer overflow. 您正在遇到无符号整数溢出。

However as the integer size may vary in between architectures it is either 32 or 64 bits long . 但是,由于整数大小在不同的体系结构之间可能会有所不同,因此长度为32位或64位

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM