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

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

WBOY
Release: 2016-06-06 20:03:53
Original
2521 people have browsed it

这篇文章主要介绍了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官网关于整型的资料:

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template