I'll be forthright about this: this one is for homework. However, as I've already completed the question and was just simply curious about different implementations of what I did, I thought it was okay to be consult y'all.
The question was to build a != function using bitwise operations. We are also allowed to use ! and +.
Returns 0 if x==y, otherwise it returns 1.
int eval_not_equal(int x, int y) {
int result = x ^ y;
if(result == 0) {
result = 0;
}
else {
result = 1;
}
return result;
}
I think this is a perfectly fine answer to the question, but I was wondering if it's possible to do this without using an if? There are quite a few different bitwise operations, and I'm sure there's gotta be a way to use them in order to replace the if that I used!
Would love to know what you guys think! :-)