Modular Arithmetic - UTEP Math Department

Download Report

Transcript Modular Arithmetic - UTEP Math Department

Lecture 11
Modular Basics

 Modular arithmetic is arithmetic in which numbers do
not continue forever.
 Modulo 7 has numbers 0, 1, 2, 3, 4, 5, and 6.
 Modulo 5 has numbers 0, 1, 2, 3, and 4.
 In general, modulo n has numbers 0, 1, 2, …, n-1.
Clocks and
Calendars

 Clocks start over at 12 and/or 24 hours.
 Calendars start over after
 7 days for one week
 52 weeks for one year
 365 days for one year
 You must pay attention to going forward in time and
going backward in time in order to add or subtract
from where you are.
Clock Examples

 Class starts at 2:30 PM on Thursday.
 If I assign a paper due 145 hours from the start of
class, when will it be due?
 If you had a paper due that was assigned 80 hours
prior, when was it assigned?
145 hours after 2:30
PM

If we divide 145 hours by 24 (hours in a day), we find 6
whole days and a decimal.
Subtracting 6 from our quotient we find 0.041666667
remaining. That is, 0.0416666 of a 24 hour period.
Multiply this decimal portion by 24 to see how many
hours it represents – 24(0.0416666667) = 1.
That is, this assignment is due 145 hours, or 6 days and
1 hour from the start of class. It would be Wednesday at
3:30 PM.
80 hours prior to
2:30 PM

Once again we divide 80 by 24 to get 3.333333.
This means three days prior and 0.333333 of 24
hours…24(0.3333333) = 8 hours.
Three days prior to Thursday is Monday and 8 hours
prior to 2:30 is 6:30 AM.
This assignment was given at 6:30 AM on Monday and
due 80 hours later on Thursday at 2:30 PM.
Calendar Examples

 April 20th, 2014 falls on a Sunday.
 What day of the week was 4/20 in 1980?
 What is the next year that 4/20 falls on a Sunday?
4/20/1980

 The first thing we should do is determine which years
were leap years (366 days) and which were not (365
days).
 Leap day occurs in any year that is evenly divisible
by 4 (with an exception that doesn’t arise in our
example).
 Leap years between 1980 and now were in 1980,
1984, 1988, 1992, 1996, 2000, 2004, 2008, and
2012.

 We know that from April 20th to April 20th is a year.
We can count the whole years and the leap years,
multiplying appropriately to find the number of days.
 1980 is a leap year, but April 20th is after leap day so
it won’t count. There are 8 leap years and 26 nonleap years.
 This makes 366x8=2928 and 26x365=9490 days,
respectively, for a total of 12, 418 days.

 In order to determine the day of the week, we now
divide this number of days by 7 to get 1774 with no
decimal.
 No decimal tells us it was exactly 1774 weeks
prior…4/20 fell on a Sunday in 1980.
4/20 next time on
Sunday

 In 2015, it will be a Monday.
 2016 is a leap year so will be Wednesday.
 2017 will be Thursday.
 2018 will be Friday.
 2019 will be Saturday.
 2020 is a leap year so will be a Monday… D’oh!
 2021 Tuesday, 2022 Wednesday, 2023 Thursday,
2024 Saturday, 2025 will be the next time 4/20 falls
on a Sunday.
Check Digits

 Check digits are a system for us to make sure the
input numbers are correct in a variety of sources.
 Check digits allow us to detect errors through a
variety of systems.