XOR Conditional

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {
	var boolA:Boolean = false;
	var boolB:Boolean = false;
	
	if (mouseX > 200){
		boolA = true;
	}else{
		boolA = false;
	}
	
	if (mouseY < 200){
		boolB = true
	}else{
		boolB = false;
	}
	
	if (boolA || boolB){
		trace("regular or");
	}
	
// this is the XOR conditional
	if (int(boolA) ^ int(boolB)){
		trace("exclusive or");
	}
	
}

There’s an obvious more logical ways to do this. But I thought it was somewhat interesting to see….

So in binary XOR will give us:
0^0 = 0;
0^1 = 1;
1^0 = 1;
1^1 = 0;

What other operator might you use to get the same results?… that’s right !=

With regular OR we get:
0|0 = 0;
0|1 = 1;
1|0 = 1;
1|1 = 1;

Leave a Reply

Your email address will not be published. Required fields are marked *