YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Modulus Operator - Intro to Computer Science

Get Embed Code
2 Languages

Showing Revision 6 created 07/06/2017 by Dejan Trajkovic.

  1. So to get our outputs in the correct range,
  2. we're going to use the Modulus Operator. And this
  3. is written with a percent sign. It's usually the
  4. Shift 5 on most keyboards. What modulus does is
  5. takes a number and maps it to the range
  6. based on the remainder when you divide that number.
  7. So the way modulo arithmetic works, is like a
  8. clock. So if we think of having a clock with
  9. 12 hours, and then arithmetic on the clock is modulo 12. So if we
  10. were to evaluate 14 modulo 12, what that would mean is,
  11. well, if we start from 0, and we make 14 steps, we're
  12. going to 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  13. 12, 13, 14. Where we end up is 2. That's the same
  14. as the remainder we would get by dividing 14 by 12. And
  15. that's the result of 14 modulo 12, is 2. So now we're
  16. going to have a few quizzes, to make sure you that understand the
  17. Modulus Operator, as well as the ord and char operators we introduced.