Extension de l'approche de Jim consistant à utiliser add pour XOR et à utiliser certaines fonctions matricielles pour supprimer les boucles... et une table ASCII.
Ceux-ci ne sont pas testés, assurez-vous qu’ils font ce que vous attendez.
char_xor = Function( {a, b}, {aa, bb},
aa = Blob To Matrix( Char To Blob( a ), "int", 1, "little" ); // string to matrix...
bb = Blob To Matrix( Char To Blob( b ), "int", 1, "little" ); // "0" -> 48, "1" -> 49
cc = Mod( aa + bb, 2 ); // XOR, 48+48->0, 48+49->1, 49+49->0
Blob To Char( Matrix To Blob( cc + 48, "int", 1, "little" ) ); // 0->48, 1->49
);
char_or = Function( {a, b}, {aa, bb},
aa = Blob To Matrix( Char To Blob( a ), "int", 1, "little" ); // string to matrix...
bb = Blob To Matrix( Char To Blob( b ), "int", 1, "little" ); // "0" -> 48, "1" -> 49
cc = aa + bb != 96; // OR, 96 is "0"+"0" == 48+48
Blob To Char( Matrix To Blob( cc + 48, "int", 1, "little" ) ); // 0->48, 1->49
);
char_and = Function( {a, b}, {aa, bb},
aa = Blob To Matrix( Char To Blob( a ), "int", 1, "little" ); // string to matrix...
bb = Blob To Matrix( Char To Blob( b ), "int", 1, "little" ); // "0" -> 48, "1" -> 49
cc = Mod( aa, 2 ) :*</img> Mod( bb, 2 ); // AND, :*</img> is element-wise. multiply 0*0, 1*0, 0*1, 1*1
Blob To Char( Matrix To Blob( cc + 48, "int", 1, "little" ) ); // 0->48, 1->49
);
char_not = Function( {a},
Substitute( a, "0", "*", "1", "0", "*", "1" ); // NOT
);
// tests
Show( char_xor( "0011", "0101" ) == "0110",
char_or( "0011", "0101" ) == "0111",
char_and( "0011", "0101" ) == "0001",
char_not( "01" ) == "10" );
p = "00110000011111";
q = "01010101011100";
Show( p, q, char_not( char_and( p, q ) ) == char_or( char_not( p ), char_not( q ) ) ); // De Morgan's Theorem
Vous souhaiterez peut-être vérifier les erreurs pour les mauvais caractères tels que "010130101".
Ouah. Le substitut n’a pas fonctionné comme je le pensais.
Voici une façon de résoudre le problème

For( i = 1, i <= 1, i = i + 15,
loops = Ceiling( Length( :A ) / 15 );
val = "";
For( i = 1, i <= Length( :A ), i = i + 15,
Asub = Substr( :A, i, 15 );
absLength = Length( Asub );
zeros = Repeat( "0", absLength );
Bsub = Substr( :B, i, 15 );
Csub = Sum( Num( Asub ), Num( Bsub ) );
Csub = Format( Csub, "Fixed Dec", 15, 0 );
If( Length( Csub ) != absLength,
Csub = Substr( zeros, 1, absLength - Length( Csub ) ) || Csub
);
val = val || Csub;
);
val = Substitute( val, "2", "0" );
)