Hacker News new | ask | show | jobs
by russtrotter 1494 days ago
The old C bum in me says this should really be a bitwise AND with 1 but I'm sure modern compilers and JS JIT/V8 runtimes optimize MOD 2 to the same.
1 comments

I spend most of my time writing C for embedded systems. You should focus first on making life easy for the people reading your code. Use `% 2` and `* 4` when those are the things you mean, rather than `& 1` and `<< 2`. Compilers have been able to do those strength reductions on their own for years, and in most cases even if the compiler didn't, the cycles you'd save aren't worth it.