I have a function djb2
on php and javascript,
php
function hash_djb2($str){
$hash = 5381;
$length = strlen($str);
for($i = 0; $i < $length; $i++) {
$hash = (($hash << 5) + $hash) + $str[$i];
}
return $hash;
}
and javascript
djb2Code = function(str){
var hash = 5381;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash << 5) + hash) + char; /* hash * 33 + c */
}
return hash;
}
on php I call
hash_djb2("123456789egrdhfdtjdtjdtjrt");
and the output is
-4235984878
and in javascript I call
djb2Code("123456789egrdhfdtjdtjdtjrt");
and the output is
27338942
Why is that and how can I fix it?
Thank you