4 ms·
I figured out the solution of using addition directly. A caveat with addition is that addition can grow the number of significant bits needed, and thus overflow
by Findecanor 1y ago
I figured out the solution of using addition directly.
A caveat with addition is that addition can grow the number of significant bits needed, and thus overflow (for large-enough values of n).
One aspect of XOR is that it is the same as binary addition without carry, and therefore it does not overflow.
- gblargg 1y agoUse unsigned (modulo) and overflow doesn't affect the result.