日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 整数转换为32 位,PHP哈希函数返回一个整数(32位int)(PHP hashing function that returns an integer (32bit int))...

發布時間:2024/10/8 php 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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))...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。