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
3
u/Aphix Apr 15 '21
This should be on your business card, and available as an NFT.