Home > Backend Development > PHP Tutorial > PHP中把有符号整型转换为无符号整型方法_PHP

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

WBOY
Release: 2016-05-30 08:47:54
Original
987 people have browsed it

在一个短地址项目中,根据六位字符与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

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template