JSFiddle - React, Tailwind, and code Playground
JavaScript
// Bitwise xor:
// If signs are the same: either 0 (numbers are same too) or positive ++++++
// If signs are different: negative in all cases ------
function checkSignsWeird(a,b){
var output = "";
if(a^b < 0){
output = "The "+a+" and "+b+" have DIFFERENT signs.";
}else{
output = "The "+a+" and "+b+" have the SAME sign.";
}
console.log(output);
}
console.group("checkSignsWeird");
checkSignsWeird(-50,40);
checkSignsWeird(60,70);
console.groupEnd()
function checkSignsGood(a,b){
var output = "";
var xorResult = a^b;
if(xorResult < 0){
output = "The "+a+" and "+b+" have DIFFERENT signs.";
}else{
output = "The "+a+" and "+b+" have the SAME sign.";
}
console.log(output);
}
console.group("checkSignsGood");
checkSignsGood(-50,40);
checkSignsGood(60,70);
console.groupEnd()
function whichSideOfZero(num){
var output = "";
if(num < 0){
output = "They have DIFFERENT signs as their bitwise xor is smaller than 0: "+num+".";
}else{
output = "They have the SAME signs as their bitwise xor is larger than or equal to 0: "+num+".";
}
console.log(output);
}
console.group("whichSideOfZero");
whichSideOfZero(-50^40);
whichSideOfZero(60^70);
console.groupEnd()