Home >php教程 >php手册 >PHP中把有符号整型转换为无符号整型方法,php整型

PHP中把有符号整型转换为无符号整型方法,php整型

WBOY
WBOYOriginal
2016-06-13 09:03:031280browse

PHP中把有符号整型转换为无符号整型方法,php整型

在一个短地址项目中,根据六位字符与ID的相互映射的算法,当ID超过2147483647的时候,六位字符的短地址映射的ID变成有符号的整型。

复制代码 代码如下:
ID        >     六位字符    >映射ID   

ID: 2147483644 > TfffVQ > 2147483644
ID: 2147483645 > efffVQ > 2147483645
ID: 2147483646 > NfffVQ > 2147483646
ID: 2147483647 > ffffVQ > 2147483647
ID: 2147483648 > nnnnnu > -2147483648
ID: 2147483649 > dnnnnu > -2147483647
ID: 2147483650 > rnnnnu > -2147483646

需要把有符号整型转换为无符号整型:(float) sprintf('%u', $id)

PHP官网关于整型的资料:http://php.net/manual/zh/language.types.integer.php

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