Example #1
0
echo 'dec($a) = [', bi_to_str($c), "]<br/>\n";
$c = bi_sqr($a);
echo 'sqr($a) = [', bi_to_str($c), "]<br/>\n";
echo 'cmp($a, $b) = ', bi_cmp($a, $b), "<br/>\n";
echo 'cmp_abs($a, $b) = ', bi_cmp_abs($a, $b), "<br/>\n";
echo 'is_zero($a) = ', bi_is_zero($a) ? 'true' : 'false', "<br/>\n";
echo 'is_one($a) = ', bi_is_one($a) ? 'true' : 'false', "<br/>\n";
echo 'sign($a) = ', bi_sign($a), "<br/>\n";
/*
    bitset functions
*/
echo '<h3>bitset functions</h3>' . "\n";
echo '<div style="text-align:right">';
echo '$a = [', bi_to_str($a, 2), "]<br/>\n";
echo '$b = [', bi_to_str($b, 2), "]<br/>\n";
$c = bi_or($a, $b);
echo '$a or $b = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_xor($a, $b);
echo '$a xor $b = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_and($a, $b);
echo '$a and $b = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_andnot($a, $b);
echo '$a andnot $b = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_set_bit($a, 0);
echo 'set_bit($a, 0) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_clr_bit($a, 0);
echo 'clr_bit($a, 0) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_inv_bit($a, 0);
echo 'inv_bit($a, 0) = [', bi_to_str($c, 2), "]<br/>\n";
$c = bi_subint($a, 10, 20);
echo 'subint($a, 10, 20) = [', bi_to_str($c, 2), "]<br/>\n";
Example #2
0
 /**
  * Calculates bitwise or of $num1 and $num2,
  * starting from bit $start_pos for number $num1
  *
  * @param big_int resource $num1
  * @param big_int resource $num2
  * @param int $start_pos
  * @return big_int resource
  * @access public
  */
 function bitOr($num1, $num2, $start_pos)
 {
     return bi_or($num1, $num2, $start_pos);
 }
Example #3
0
*/
require_once dirname(__FILE__) . '/std_header.php';
$a = bi_from_str('1110110110110101011000100010110011101110111', 2);
$b = bi_from_str('11010010101111101010000101010100011101', 2);
echo '$a = ', bi_to_str($a, 2), "\n";
echo '$b = ', bi_to_str($b, 2), "\n";
////////////////////////////////////////////////
$c = bi_andnot($a, $b);
echo 'bi_andnot($a, $b) = ', bi_to_str($c, 2), "\n";
$c = bi_xor($a, $b);
echo 'bi_xor($a, $b) = ', bi_to_str($c, 2), "\n";
$c = bi_or($a, $b);
echo 'bi_or($a, $b) = ', bi_to_str($c, 2), "\n";
$c = bi_and($a, $b);
echo 'bi_and($a, $b) = ', bi_to_str($c, 2), "\n";
////////////////////////////////////////////////
$c = bi_andnot($a, $b, 2);
echo 'bi_andnot($a, $b, 2) = ', bi_to_str($c, 2), "\n";
$c = bi_xor($a, $b, 5);
echo 'bi_xor($a, $b, 5) = ', bi_to_str($c, 2), "\n";
$c = bi_or($a, $b, 32);
echo 'bi_or($a, $b, 32) = ', bi_to_str($c, 2), "\n";
$c = bi_or($a, $b, 33);
echo 'bi_or($a, $b, 33) = ', bi_to_str($c, 2), "\n";
$c = bi_or($a, $b, 70);
echo 'bi_or($a, $b, 70) = ', bi_to_str($c, 2), "\n";
$c = bi_and($a, $b, 7);
echo 'bi_and($a, $b, 7) = ', bi_to_str($c, 2), "\n";
////////////////////////////////////////////////
echo '$a = ', bi_to_str($a, 2), "\n";
echo '$b = ', bi_to_str($b, 2), "\n";