Answer the question
In order to leave comments, you need to log in
How to rewrite hash function from js to php?
Good time, gentlemen, the question that interests me in the title is not trivial, I still think.
Can you tell me how, I can correctly rewrite the function written in js in php
What exactly is not clear is bitwise operations in js and in php because the function generates a hash string, you need to bring the result of the function in js as close as possible to the same function in php
Let 's say JS: var p = (C >>> 2 | C << 30);
and PHP: $p = ($C >> 2 | $C << 30)
How critical are shift differences between js >>> and php >> ?
Answer the question
In order to leave comments, you need to log in
For non-negative numbers, a right shift with zero padding >>> and a right shift with sign wrapping >> will give the same result, because in both cases zeros will be added to the left.
For negative numbers - the result of the work is different. For example, -9 >>> 2 will give 1073741821, as opposed to -9 >> 2 (yields -3).
All binary operations in js work with the int32 (signed) type, except for one - >>> which works with the uint32 type, that is, the most significant bit (in int32 this is the sign bit) is involved in the shift
. PHP has a separate type for integers, php. net/manual/en/language.types.integer.php
And its dimension depends on the platform, while it is always signed, so yes, the result may be different, on windows and 32-bit platforms, on 64-bit it will be the same
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question