in reply to Re: A mod2 Machine.

Ok, I'll be more clear. First, when I said that the arithmetic operation will take more time, I said it with respect to the mod2 machine. Second, let's take your example (just a wild guess, is this game GO)

```#!/usr/bin/perl
# note that %b modifier processes binary. Similarly, %x processes hexa
+decimal and %o is for octal.

use strict;
use warnings;

my (\$move, \$pos);
\$move = 0b1111111111111111;
\$pos = 0b0000111111111111;
printf "%b\n", (\$move ^ \$pos);

Even here, there are no arithmetical operations. Note that Exclusive Or is a logical operation. This is somewhat similar to a mod machine. You change state only if there are opposite inputs. The catch here is, if we'd have used strings instead of a number, there would've been a few more lines of code, keeping in mind and as you said, breaking the string and using regexes. I'm not saying that we should replace every arithmetic operation with string/logical operation, we just can't, I'm just trying to convey that there are better ways to do simple things that school teaches us in a very dogmatic way.

I mean seriously, why should I actually divide a number by 2 and check the remainder when I can directly check the last digit?! Or why should I recursively divide and mod by 10 to generate the reverse of a number when I can do it in one line?!

```/* Apologies for using C, but its my "mother-tongue" :P */

#include <stdio.h>

int main(int argc, char **argv)
{
int ;
for(i = (strlen(argv[1]) - 1); i >= 0; i--){
printf("%c", *(argv[1] + i)); /* reverse a string, a number, a
+ sentence, a novel... */
}
}
Note/PS: Logical operations, too, are faster than arithmetical operations afaik.

Replies are listed 'Best First'.
Re^3: A mod2 Machine.
by Laurent_R (Canon) on Jul 08, 2013 at 11:54 UTC

I think we agree.

My point is that I was using the ^ logical operation on actual binaries, something very similar to what you showed:

```my (\$move, \$pos);
\$move = 0b1111111111111111;
\$pos = 0b0000111111111111;
printf "%b\n", (\$move ^ \$pos);