This script does Addition and Subtraction without once using the + or - operators. Good example of how to use bitwise operators.
Download
View Source (print view)
Rating : 4.7
Views : 157
<?php
if (isset($num1) && isset($num2))
{
function BinaryAdd($num1,$num2)
{
$carry = $num1 & $num2;
do
{
$carry = $carry << 1;
$num1 = $num1 ^ $num2;
$sum = $num1 ^ $carry;
$num2 = $carry;
$carry = $num1 & $num2;
} while($carry != 0);
return $sum;
}
function BinarySubtract($num1,$num2)
{
//Compute Two's Compliment
$num2 = ~ $num2;
$num2 = BinaryAdd($num2,1);
$diff = BinaryAdd($num1,$num2);
return $diff;
}
//Make sure form data is treated like an int
$number1 = (int)$num1;
$number2 = (int)$num2;
$sum = BinaryAdd($number1,$number2);
$diff = BinarySubtract($number1,$number2);
echo "The Sum is $sum<BR>";
echo "The Difference is $diff";
} else {
?>
<Form Action="<? echo $PHP_SELF ?>" Method=Post>
Enter an Integer <Input Type=text name="num1"><BR>
Enter a Second Integer <Input Type=text name="num2"><BR>
<Input Type=Submit Value="Add and Subtract Them">
</Form>
<? } ?>
how to use this code, php_tools, yahoo_status_shopping_cart.php, php file upload, shopping_cart and user=0--, drop down, mysql_commit, forum, shopping_cart', backup, updateoraddimagesonpages, rtttl to 8 bit source code, stefan_hornea, rent_and_0=1_union_select, how to run php, php_script"_class="neww"_target="_blank"_title="im_neuen, embed_snippets, farah_aead, sql incection, antoine anik, i need webmail login name and password