r/shittyprogramming • u/Successful-Pay-4575 • Apr 12 '21
Stop compiler abuse
Every day, compilers are forced to convert addition into the proper xors and bit shifts, Together, we can stop this problem. Instead of using the addition operator, use this function instead:
int recursiveAdd(int a, int b) {
int xor = a ^ b;
int and = (a & b) << 1;
if (and != 0)
return recursiveAdd(xor, and);
return xor;
}
113
Upvotes
View all comments
Show parent comment
2
u/Aphix Apr 15 '21
Now make a func that uses that twice to add two numbers without any numerical operation.
Also, that is art.