How do i do a clean boolean add in javascript?
1+1 = 0;
1+0 = 1;
1+1+1 = 1;
etc. can one just sum booleans?
true+true = false
false+true = true;
etc.
Just use bitwise XOR operator:
1 ^ 1 = 0
1 ^ 0 = 1
1 ^ 1 ^ 1 = 1
FWIW: The same works for most high-level programming languages.
1+1 to be equal to 0, than he probably doesn't really look for a boolean addition, since this would give 1 as a result.
1+1supposed to be 1 in boolean addition?0 + 0 = 0,0 + 1 = 1,1 + 0 = 1and1 + 1 = 0 (with a carry over of 1). Hence boolean addition is the xor operator and the carry can be found using boolean multiplication (i.e. the and operator).1+1equals1.andand boolean addition is in factor. However I believe that the OP is looking to create a half adder. This requires the xor operation.