Hacker News new | ask | show | jobs
by ralfd 3115 days ago
Can someone explain the n modulo operation to me?
1 comments

it's an easy way to filter out odd/even numbers. `n % m` means "divide `n` by `m` and return the remainder". If you divide any even number by 2, the remainder is always 0, if you divide an odd number, it's always 1. Translate that to a boolean and you've got a nice odd/even filter.