customFunctions.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. function arraycopy($srcArray,$srcPos,$destArray, $destPos, $length){//System.arraycopy
  3. $srcArrayToCopy = array_slice($srcArray,$srcPos,$length);
  4. array_splice($destArray,$destPos,$length,$srcArrayToCopy);
  5. return $destArray;
  6. }
  7. function overflow32($value) {//There is no need to overflow 64 bits to 32 bit
  8. return $value;
  9. }
  10. function hashCode( $s )
  11. {
  12. $h = 0;
  13. $len = strlen($s);
  14. for($i = 0; $i < $len; $i++)
  15. {
  16. $h = overflow32(31 * $h + ord($s[$i]));
  17. }
  18. return $h;
  19. }
  20. function numberOfTrailingZeros($i) {
  21. if ($i == 0) return 32;
  22. $num = 0;
  23. while (($i & 1) == 0) {
  24. $i >>= 1;
  25. $num++;
  26. }
  27. return $num;
  28. }
  29. function intval32bits($value)
  30. {
  31. $value = ($value & 0xFFFFFFFF);
  32. if ($value & 0x80000000)
  33. $value = -((~$value & 0xFFFFFFFF) + 1);
  34. return $value;
  35. }
  36. function uRShift($a, $b)
  37. {
  38. if($b == 0) return $a;
  39. return ($a >> $b) & ~(1<<(8*PHP_INT_SIZE-1)>>($b-1));
  40. }
  41. /*
  42. function sdvig3($num,$count=1){//>>> 32 bit
  43. $s = decbin($num);
  44. $sarray = str_split($s,1);
  45. $sarray = array_slice($sarray,-32);//32bit
  46. for($i=0;$i<=1;$i++) {
  47. array_pop($sarray);
  48. array_unshift($sarray, '0');
  49. }
  50. return bindec(implode($sarray));
  51. }
  52. */
  53. function sdvig3($a,$b) {
  54. if ($a >= 0) {
  55. return bindec(decbin($a>>$b)); //simply right shift for positive number
  56. }
  57. $bin = decbin($a>>$b);
  58. $bin = substr($bin, $b); // zero fill on the left side
  59. $o = bindec($bin);
  60. return $o;
  61. }
  62. function floatToIntBits($float_val)
  63. {
  64. $int = unpack('i', pack('f', $float_val));
  65. return $int[1];
  66. }
  67. function fill_array($index,$count,$value){
  68. if($count<=0){
  69. return array(0);
  70. }else {
  71. return array_fill($index, $count, $value);
  72. }
  73. }