Created
May 2, 2020 14:32
-
-
Save imbyc/b4fbbf30b5e42c854b6c3334b7b00b4a to your computer and use it in GitHub Desktop.
[PHP实现JavaScript的位移运算符] https://zhile.io/2018/06/21/php-equivalent-javascript-bitwise-operators.html #无符号右移 #位运算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* >> javascript operator in php x86_64 | |
* @param int $v | |
* @param int $n | |
* @return int | |
*/ | |
function rr($v, $n) | |
{ | |
$v = $v & 0x80000000 ? $v | 0xFFFFFFFF00000000 : $v & 0xFFFFFFFF; | |
return $v >> ($n & 0x1F); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* << javascript operator in php x86_64 | |
* @param int $v | |
* @param int $n | |
* @return int | |
*/ | |
function ll($v, $n) | |
{ | |
$t = ($v & 0xFFFFFFFF) << ($n & 0x1F); | |
return $t & 0x80000000 ? $t | 0xFFFFFFFF00000000 : $t & 0xFFFFFFFF; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* >>> javascript operator in php x86_64 | |
* @param int $v | |
* @param int $n | |
* @return int | |
*/ | |
function rrr($v, $n) | |
{ | |
return ($v & 0xFFFFFFFF) >> ($n & 0x1F); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 转换效果(js to PHP): | |
// if (i = 0, j = 1, k =2) {} to if (comma($i = 0, $j = 1, $k = 2)) {} | |
/** | |
* @param ... | |
* @return mixed | |
*/ | |
function comma() | |
{ | |
$args = func_get_args(); | |
return end($args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment