Voting

: min(five, eight)?
(Example: nine)

The Note You're Voting On

admin at spamhere dot sinfocol dot org
14 years ago
Well, I have a little problem implementing Blake Hash in my server because it is not a x64 server machine. I made a little function that use the powerfull of BC library to do the bitwise operation Shift.

<?php
echo 'Left Shift test<br />';
bprint('1', decbin(1));
bprint('1 << 32 (Fail)', decbin(1 << 32)); //Fail, operation not succesfull in 32-bit machine
bprint('shiftleft(1, 32) (Success)', dec2bin(shiftleft('1', '32'))); //decbin fails, so we use personalized function, success

echo '<br />';
echo
'Right Shift test<br />';
bprint('9223372036854775808', dec2bin('9223372036854775808'));
bprint('9223372036854775808 >> 63 (Fail)', decbin(9223372036854775808 >> 63));
bprint('rightshift(9223372036854775808, 63) (Success)', decbin(rightshift('9223372036854775808', '63')));

function
shiftleft($num, $bits) {
return
bcmul($num, bcpow('2', $bits));
}

function
rightshift($num, $bits) {
return
bcdiv($num, bcpow('2', $bits));
}

function
bprint($title, $content) {
echo
$title . '<br />' . str_pad($content, 64, '0', STR_PAD_LEFT) . '<br />' . PHP_EOL;
}

//http://www.php.net/manual/en/function.decbin.php#99533
function dec2bin($dec) {
// Better function for dec to bin. Support much bigger values, but doesn’t support signs
for ($b = '', $r = $dec; $r >1;) {
$n = floor($r / 2);
$b = ($r - $n * 2) . $b;
$r = $n; // $r%2 is inaccurate when using bigger values (like 11.435.168.214)!
}
return (
$r % 2) . $b;
}
?>

<< Back to user notes page

To Top