php 整数转换为32 位,PHP哈希函数返回一个整数(32位int)(PHP hashing function that returns an integer (32bit int))...
PHP哈希函數返回一個整數(32位int)(PHP hashing function that returns an integer (32bit int))
目標是使用INT(不是BIGINT或MEDIUMINT)將散列存儲在mysql數據庫中。 md5('string', true)返回二進制數據,16個字節的散列。 我以為我可以grep前4個字節,并將其轉換為一個INT(32位/ 4字節)整數,但我不知道該怎么做。
你有什么建議? 謝謝。
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.
原文:https://stackoverflow.com/questions/8520969
更新時間:2020-01-09 11:17
最滿意答案
ord($hash[0]) * 16777216 + ord($hash[1]) * 65536 + ord($hash[2]) * 256 + ord($hash[3]) ;
要么:
unpack("L", substr($hash,0,4));
但FilipRoséen的解決方案更好。
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.
2018-01-08
相關問答
我測試了類型化數組 ,QSIP版本在現代瀏覽器中似乎很好: 200萬個元素 QSIP_TYPED | RDXIP_TYPED | QSIP_STD | RDXIP_STD
----------------------------------------------------------
Chrome | 300 1000 600 1300
Firefox | 550 1500
...
正如在評論中提到的,你必須先倒過來然后檢查。 然而,這是一種不同的檢查方式。 要檢查你可以用適當的掩碼&結果。 所以在你的情況下,限制是?2,147,483,648和2,147,483,647 ,它們的十六進制值是-0x80000000和0x7fffffff 在解釋器中試試這個。 >>> 0x7fffffff
2147483647
>>> 2147483647 & 0x7fffffff #within limit
2147483647
超出限制的值,可以看到顯示其他一些值。 >>> 2147
...
很快,您可以在Javascript中使用Math對象 Javascript不知道它是否是INT。 它只知道數字。 然后將一個字符串附加到數字只需執行以下操作: var my_int = 45.25;
var my_str = 'Hello Wolrd';
document.write(my_int+my_str); // echo 45.25Hello World
Quickly , you could use the Math object in Javascript Javascript
...
以下是如何在舊SDK中的“ NSObjCRuntime.h ”中定義“ NSInteger ”: #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigne
...
工會是否可以搬運? 如果是這樣,這是一個很好的方法...... union {
struct {
unsigned char CharArray[8];
} ub;
struct {
unsigned long int IntArray[2];
} ul;
unsigned long long ull;
} Foo;
Does a union work portably? If so, it's a good approac
...
整數是該平臺上指針的大小。 (32位PHP - > 32位整數.64位PHP - > 64位整數)。 請注意,當整數運算溢出時,變量變為浮點數。 PHP文檔很好地解釋了所有這些。 我不確定你在代碼中做了什么會導致你關心整數的大小。 但是,如果您只關心32位的值,則可以始終屏蔽低32位: $val = $something & 0xFFFFFFFF;
Integers are the size of pointers on that platform. (32-bit PHP --> 32-bit
...
ord($hash[0]) * 16777216 + ord($hash[1]) * 65536 + ord($hash[2]) * 256 + ord($hash[3]) ;
要么: unpack("L", substr($hash,0,4));
但FilipRoséen的解決方案更好。 ord($hash[0]) * 16777216 + ord($hash[1]) * 65536 + ord($hash[2]) * 256 + ord($hash[3]) ;
Or: unpack("L
...
如果你需要精確度,你不應該使用浮點數。 相反,特別是當你想使用整數( 如果我理解正確的話 ),你可以嘗試使用gmp*函數: GMP - GNU Multiple Precision 如果你不能使用這個擴展,你可能會從中得到一些額外的想法 PEAR Big Integer - Pure-PHP任意精度整數算術庫 If you need precision, you should not use floats. Instead, especially as you want to work with
...
當number達到0時終止循環。 此時不再有非零位: public static string ConvertIntToBinary(uint value)
{
int totalbits = sizeof(int) * 8;
char[] result = new char[totalbits];
int bits = totalbits;
uint number = value;
while (bits > 0)
{
bits-
...
在乘以10之前,只需檢查以確保它足夠小以乘以10。 同樣,在添加remainder之前,請檢查以確保它足夠小以添加remainder 。 有一個聰明的技巧可以用來添加,但在你的水平你可能不應該: if ((reversed += remainder) < remainder) {
//overflow
}
請注意,只有當reversed和remainder都是無符號時,該技巧才有效。 Before you multiply reversed by 10, just check to ma
...
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的php 整数转换为32 位,PHP哈希函数返回一个整数(32位int)(PHP hashing function that returns an integer (32bit int))...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 笔记本怎么开启快捷键是什么意思 笔记本开
- 下一篇: nginx无法访问index.html,