3 ms·
> ...solving “How do you tell if a number is even or odd” with clumsy solutions such as (x % 2). They don’t [...] come to the conclusion that (most) computers a
by T-R 16y ago
> ...solving “How do you tell if a number is even or odd” with clumsy solutions such as (x % 2). They don’t [...] come to the conclusion that (most) computers are digital machines, all you have to do is check the first bit (x & 1).
Not to be nitpicky, since your overall point still stands, but I'd argue that it's better to use a mathematical abstraction (modulo) than an optimization that's dependent on the way the data is stored (bitwise operations), particularly when the compiler will probably optimize it away anyway.
- chalst 16y agoNot to mention that there are many small PLs that don't have bitwise operators.