To say they just add is a bit off...adding a negative of a number IS subtraction. And the process of shifting a bit right or left IS multiplication and division. Just because a CPU converts everything to binary doesn't mean that it's no longer mathematics. Even the most basic ALU makes the mathematics even more like what you are describing as 'math'...since it allows logical 'shortcuts' that speed mathematics using cpu architecure using some of the same rules that we use to do the calculations. ie 1 AND 0 = 0 is equivalent to 1*0=0 or 7*0=0 is equivalent to (1011 AND 0000) = 0000...using bitwise operations, and one's and two's complements at the most basic level make these calculations easier for a computer. More advanced ALU's (those made since the 80's) actually can do multiplication and division in every way...it's still with 1 or 0 bits, but just because a Frenchman uses french numbers to calculate Pi doesn't mean he's not doing math by US standards...
Anyway:
1%1=0
2%1=0
3%1=0
...
2%2=0
3%2=1
4%2=0
5%2=1
...
3%3=0
4%3=1
5%3=2
6%3=0
...
It's not called the remainder function, btw, it is the modulo or mod function...see Modulo operation - Wikipedia, the free encyclopedia for more
Code:
#!/usr/bin/env perl
# Perl ftw!
$a = shift;
$b = shift;
if ($a>$b)
{
if ($a%$b==0)
{
printf("%d is a multiple of %d\n",$a,$b);
}
else
{
printf("%d is NOT a multiple of %d",$a,$b);
}
}
else
{
if ($b%$a==0)
{
printf("%d is a multiple of %d\n",$b,$a);
}
else
{
printf("%d is NOT a multiple of %d",$b,$a);
}
}
exit(0);
Anyway, that could be done better swapping them out, but this should show you that you would want the larger number before the % and the smaller after....after all, something is never going to be described as a multiple of something larger than itself...