clock arithmetic
play

Clock Arithmetic 7 January 2019 OSU CSE 1 Mathematical Modulo - PowerPoint PPT Presentation

Clock Arithmetic 7 January 2019 OSU CSE 1 Mathematical Modulo (mod) The value of a mod b , or a modulo b , where a and b are mathematical integer s and b > 0 , is computed by doing clock arithmetic on a clock face with b positions


  1. Clock Arithmetic 7 January 2019 OSU CSE 1

  2. Mathematical Modulo (“mod”) • The value of a mod b , or a modulo b , where a and b are mathematical integer s and b > 0 , is computed by doing clock arithmetic on a clock face with b positions – If a > 0 , the “hand” on the clock starts at 0 and moves |a| positions clockwise – If a < 0 , it moves |a| counter-clockwise – Where it ends up is the value of a mod b 7 January 2019 OSU CSE 2

  3. Example: 24-hr Clock 7 January 2019 OSU CSE 3

  4. Example: 24-hr Clock Any integer mod 24 is a number between 0 and 23 inclusive. 7 January 2019 OSU CSE 4

  5. Example: 24-hr Clock What is 67 mod 24 ? Twice around is 48, and 19 more makes 67. Hence, 19. 7 January 2019 OSU CSE 5

  6. Example: 24-hr Clock And (–67) mod 24 ? Hint: it is not 19 , it is not –19 , but rather… 7 January 2019 OSU CSE 6

  7. Example: 24-hr Clock And (–67) mod 24 ? Hint: it is not 19 , it is not –19 , but rather 5 . 7 January 2019 OSU CSE 7

  8. Modulo ≠ Remainder ( % ) • What is the remainder upon dividing 67 by 24? It is 19. • What is the remainder upon dividing –67 by 24? It is –19. – At least most people would say it is, and indeed this is how Java evaluates the expression: (-67) % 24 7 January 2019 OSU CSE 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend