so I'm bruteforcing some stuff using comparator subtraction logic to look for patterns that will let me do XOR.
I've been able to use subtraction and inversion to achieve an XOR equivalent function on all possible values except for when there is a combination of two from the following list:
3: 0011
5: 0101
6: 0110
9: 1001
10: 1010
12: 1100
It's pretty interesting how the problematic values always contain 2 bits.
Here is the code i rigged up to mess with stuff:
http://pbin.in/hax
... and yes I overloaded ! to be hex inversion, don't kill me D:
I've been able to use subtraction and inversion to achieve an XOR equivalent function on all possible values except for when there is a combination of two from the following list:
3: 0011
5: 0101
6: 0110
9: 1001
10: 1010
12: 1100
It's pretty interesting how the problematic values always contain 2 bits.
Here is the code i rigged up to mess with stuff:
Code:
#include <iostream>
using namespace std;
class ComparatorBasic{
public:
ComparatorBasic(int input = 0x0, int sideA = 0x0, int sideB = 0x0){
in(input);
side(sideA, sideB);
}
int out(){return _round(_in-_side);}
void in(int val){
_in = _round(val);
return;
}
void side(int a){
side(a, 0x0);
return;
}
void side(int a, int b){
if(a>=b) _side = _round(a);
else _side = _round(b);
return;
}
private:
int _in;
int _side;
int _round(int val){
if(val<0x0) return 0x0;
else if(val>0xF) return 0xF;
else return val;
}
};
class Comparator{
public:
Comparator(int val = 0x0){_value = ComparatorBasic(val).out();}
Comparator operator-(Comparator val){
return Comparator(ComparatorBasic(_value, val.value()).out());
}
Comparator operator-(int val){
return operator-(Comparator(val));
}
Comparator operator!(){
return Comparator(0xF)-_value;
}
Comparator operator+(Comparator val){
return !(!val - _value);
}
Comparator operator+(int val){
return operator+(Comparator(val));
}
void operator=(Comparator val){
_value = val.value();
return;
}
void operator=(int val){
_value = ComparatorBasic(val).out();
return;
}
void operator+=(Comparator val){
operator=(operator+(val));
return;
}
void operator+=(int val){
return operator+=(Comparator(val));
}
bool operator==(Comparator val){
return _value==val.value();
}
bool operator==(int val){
return _value==val;
}
int value(){return _value;}
void bin(){
for(int i=8; i>0; i/=2) cout << bool(_value&i);
return;
}
private:
int _value;
};
void test(Comparator A, Comparator B){
Comparator val[2][2] = {
A, !A,
B, !B,
};
Comparator target = A.value()^B.value();
bool success = false;
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
for(int k=0; k<2; k++){
Comparator result = val[i][j] - val[i^1][k];
if((result == target)||(!result == target)){
success = true;
if(!result == target) cout << "!(";
if(j) cout << '!';
val[i][0].bin();
cout << " - ";
if(k) cout << '!';
val[i^1][0].bin();
if(!result == target) cout << ')';
cout << " == ";
A.bin();
cout << " ^ ";
B.bin();
cout << endl;
}
}
}
}
if(!success){
cout << "Unable to acheive XOR for ";
A.bin();
cout << " ^ ";
B.bin();
cout << endl;
}
return;
}
int main(){
for(int i=0; i<16; i++){
for(int j=i; j<16; j++){
test(Comparator(i), Comparator(j));
}
}
return 0;
}
http://pbin.in/hax
... and yes I overloaded ! to be hex inversion, don't kill me D: