PHP哈希函数返回一个整数(32位int) [英] PHP hashing function that returns an integer (32bit int)
本文介绍了PHP哈希函数返回一个整数(32位int)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目标是使用INT(不是BIGINT或MEDIUMINT)将散列存储在mysql数据库中。
md5('string',true)
返回二进制数据,16个字节的散列。我以为我可以grep的前4个字节,并将其转换为一个INT(32位/ 4bytes)整数,但我不知道该怎么做。
什么做你建议?谢谢。
解决方案
ord($ hash [0])* 16777216 + ord($ hash [1])* 65536 + ord($ hash [2])* 256 + ord($ hash [3]);
或者:
unpack(L,substr($ hash,0,4));
但FilipRoséen的解决方案更好。
The goal is to store the hash on a mysql database, using INT (not BIGINT or MEDIUMINT).
md5('string', true)
returns binary data, 16 bytes of hash. I thought i could grep the first 4 bytes and convert it to an INT(32bit/4bytes) integer, but i don't know how to do it.
What do you suggest? Thanks.
解决方案
ord($hash[0]) * 16777216 + ord($hash[1]) * 65536 + ord($hash[2]) * 256 + ord($hash[3]) ;
Or:
unpack("L", substr($hash,0,4));
But Filip Roséen's solution is better.
这篇关于PHP哈希函数返回一个整数(32位int)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文