
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question

Transcribed Image Text:Computer Time is Based on Milliseconds
• Generally, we count time in computer software in milliseconds (thousandths of a second) since 1970/01/01 01:00:00 - that is 1AM on 1st January 1970.
• You might think "that's over 50 years of milliseconds - it must be a huge number". And you'd be right - in fact, the number will get too big to store in "normal" ints in 2038 (not just for Java) - an
now uses the long datatype instead of int to store time values (these won't run out for nearly 300 billion years).
• Working with time in Java (and other languages) basically involves using built-in libraries to convert time to/from milliseconds.
You'll also need (maybe.) to be able to covert milliseconds to seconds (divide by 1000), minutes (divide again by 60) and hours (should be clear what you need to do now).
• There are several libraries for this in Java - which is (a) confusing and (b) dangerous since some are now deprecated (as in you shouldn't use them).
• We will be using two - LocalDateTime (for actually handling dates) and DateTimeFormatter (for turning strings into dates) - both of which are up to date.
• In common with standard practice when we say "date" we mean "date and time".
The 'long' Datatype
Because the numbers we are dealing with are potentially very large, we need to use long not int. Using long is basically the same as using int except that you generally need to put an Lon the end
prevent Java compiler errors because numbers are too large. For example:
long example - 1996614713000L; //1998614713000 without the L Nould be too big - the L forces it to be a long
DateTimeFormatter
We will use the date format: year/month/day hour:mins:secs to represent dates as a String, where each of the components is two digits except year, which is four. To do this we first need to creat
DateTimeFormatter of - DatetimeFormatter.ofPattern("yyyy/vad HH: mm:55");
This creates an object df which we can use to both parse dates (turn strings in the above format into milliseconds) and generate date strings (turn milliseconds into strings representing dates).
You need to have the import statement:
Import java.time.format.DateTineFornatter;
in your code
LocalDateTime
This needs the import statements:
import java.time.Instant;
import java.time.LocalDateTime;
import java.tine.Zoneid;
And you'll need two different kinds of code fragments. To turn a String in the format above into milliseconds:
long milliseconds - LocalDateTime.parse(date, of).atzone(Zoneld.systemDefault()).toInstant().toEpochtilli():
where date is a string in the format above, and df is the DateTimeFormatter above. Note that the result is a long, not an int!
To turn milliseconds back into a String (which depending on how you approach the problems you may not have to do):
LocalDatetime dnils - LocalDateTine.ofInstant(Instant.ofEpochMilli (millis), Zoneid.systemDefault());
String datestring- oniis.fornat (of);
where millis is a long (not an int!) representing the date in milliseconds.
Danger!
If you look at the documentation for LocalDateTime you'll find a lot of methods to do with e.g. hours, minutes and seconds - you might think these might come in handy to convert from millisecond
you might first think they do and are unlikely to be useful (except to waste valuable time).
Q1
Time: Which of the pairs of dates below is separated by 178665918000L milliseconds?
O 1998/03/16 22:03:02 and 2003/12/01 08:01:46
1998/03/22 03:40:40 and 2003/11/06 23:47:43
1998/03/29 20:59:25 and 2003/12/11 09:14:32
1998/03/16 13:29:46 and 2003/11/07 22:56:07
O 1998/04/03 01:27:45 and 2003/11/30 21:53:03
![Q2
Time: Which of the dates below is 735764000L milliseconds from the date 2047/10/29 20:37:58?
O 2047/10/29 20:40:03
O 2047/11/07 09:00:42
O 2047/10/29 20:31:20
2047/10/29 20:41:17
O 2047/10/29 20:44:39
Q3
Time: Suppose you are at time traveller and travel through the sequence of dates in the following list,how many milliseconds would you have travelled through? Note
that going backwards in time does not mean you 'subtract'milliseconds - the time you travel through (forwards or backwards) always adds on to the time you have
travelled through up to that point. For example, if you travelled from 1st Jan 2021 to 1st Jan 2022, and then back to 1st Jan 2021 you would have travelled through
two years of time (note though that the question is asking for an answer in milliseconds).
String datelist[] - ("1979/08/02 13:45:22", "2069/88/23 19:08:58", "2004/04/29 23:47:47", "1998/06/27 19:06:14", "1982/03/19 23:08: 20", "2005/12/e4 07:50:11", "2046/e2/17
15:04:55", "1988/e7/22 14:38:36", "2040/09/26 10:29:22", "1985/05/29 e1:11:54", "1979/09/02 00:45:03", "2047/12/26 02:22:25", "1999/02/08 22:04:28", "2064/06/28 08:53:34",
*2052/02/21 10:04:27", "2040/11/19 20:17:10", "2053/01/08 21:03:03", "2053/02/07 04:30:32", "2050/05/13 02:44:23", "2021/06/25 14:47:42", "2056/02/01 19:51:28", "2026/11/0
9 17:48:33", "2060/11/21 12:03:58", "2005/10/26 14:17:26", "2060/01/88 e0:02:48", "2035/10/22 19:09:06", "197e/e2/27 07:16:40", "2064/08/01 e7:00:45", "1998/10/18 e9:44:0
2", "2010/07/29 00:31:28", "2003/05/29 e5:37:17", "1974/10/25 02:30:02", "1985/04/10 19:01:32", "2054/02/25 18:55:45", "2058/05/11 01:41:32", "2068/06/10 08:34:34", "2047/
03/05 17:41:35", "2043/04/16 19:57:30", "2035/12/18 16:09:05", "1984/12/15 13:27:20", "1975/06/09 10:53:59", "2031/12/12 15:08:35", "2025/09/02 e1:49:36", "2048/03/08 e7:4
4:57", "2056/07/07 13:43:48", "2041/11/04 22:25:02", "2052/06/17 05:39:24", "2026/02/03 06:23:53", "1995/10/17 20:44:45", "1977/02/11 16:32:17", 2043/11/03 16:02:18", "19
88/04/08 19:04:12", "2027/06/01 21:30:12", *2028/11/07 16:44:32", "1974/04/07 07:47:36", "2063/09/24 17:38:18", "2043/05/03 12:27:28", "1999/12/17 02:33:33", "1988/03/04 0
0:37:31", "1974/12/24 07:08:55", "2057/03/24 03: 22:31", "1983/03/22 13:48:29", "2028/05/06 06:39:46", "2059/04/23 21:00:12", "1971/12/27 19:52:01");
O 71916709378000
O 71916709878000
O 71916709871000
O 71916709322000
O 71916710154000
Q4
Time: Which of the times in the following list are closest to hour 811836 since 1970/01/01 01:00:00?
O 2062/07/17 08:06:40
O 2062/07/19 20:41:57
O 2062/08/25 01:23:54
2062/08/12 13:38:34
2062/08/16 14:02:27](https://content.bartleby.com/qna-images/question/f0197141-ca3d-4158-97e1-0ac184349579/c2ea1cac-f265-406c-873a-67923644025a/zs5nt2_thumbnail.jpeg)
Transcribed Image Text:Q2
Time: Which of the dates below is 735764000L milliseconds from the date 2047/10/29 20:37:58?
O 2047/10/29 20:40:03
O 2047/11/07 09:00:42
O 2047/10/29 20:31:20
2047/10/29 20:41:17
O 2047/10/29 20:44:39
Q3
Time: Suppose you are at time traveller and travel through the sequence of dates in the following list,how many milliseconds would you have travelled through? Note
that going backwards in time does not mean you 'subtract'milliseconds - the time you travel through (forwards or backwards) always adds on to the time you have
travelled through up to that point. For example, if you travelled from 1st Jan 2021 to 1st Jan 2022, and then back to 1st Jan 2021 you would have travelled through
two years of time (note though that the question is asking for an answer in milliseconds).
String datelist[] - ("1979/08/02 13:45:22", "2069/88/23 19:08:58", "2004/04/29 23:47:47", "1998/06/27 19:06:14", "1982/03/19 23:08: 20", "2005/12/e4 07:50:11", "2046/e2/17
15:04:55", "1988/e7/22 14:38:36", "2040/09/26 10:29:22", "1985/05/29 e1:11:54", "1979/09/02 00:45:03", "2047/12/26 02:22:25", "1999/02/08 22:04:28", "2064/06/28 08:53:34",
*2052/02/21 10:04:27", "2040/11/19 20:17:10", "2053/01/08 21:03:03", "2053/02/07 04:30:32", "2050/05/13 02:44:23", "2021/06/25 14:47:42", "2056/02/01 19:51:28", "2026/11/0
9 17:48:33", "2060/11/21 12:03:58", "2005/10/26 14:17:26", "2060/01/88 e0:02:48", "2035/10/22 19:09:06", "197e/e2/27 07:16:40", "2064/08/01 e7:00:45", "1998/10/18 e9:44:0
2", "2010/07/29 00:31:28", "2003/05/29 e5:37:17", "1974/10/25 02:30:02", "1985/04/10 19:01:32", "2054/02/25 18:55:45", "2058/05/11 01:41:32", "2068/06/10 08:34:34", "2047/
03/05 17:41:35", "2043/04/16 19:57:30", "2035/12/18 16:09:05", "1984/12/15 13:27:20", "1975/06/09 10:53:59", "2031/12/12 15:08:35", "2025/09/02 e1:49:36", "2048/03/08 e7:4
4:57", "2056/07/07 13:43:48", "2041/11/04 22:25:02", "2052/06/17 05:39:24", "2026/02/03 06:23:53", "1995/10/17 20:44:45", "1977/02/11 16:32:17", 2043/11/03 16:02:18", "19
88/04/08 19:04:12", "2027/06/01 21:30:12", *2028/11/07 16:44:32", "1974/04/07 07:47:36", "2063/09/24 17:38:18", "2043/05/03 12:27:28", "1999/12/17 02:33:33", "1988/03/04 0
0:37:31", "1974/12/24 07:08:55", "2057/03/24 03: 22:31", "1983/03/22 13:48:29", "2028/05/06 06:39:46", "2059/04/23 21:00:12", "1971/12/27 19:52:01");
O 71916709378000
O 71916709878000
O 71916709871000
O 71916709322000
O 71916710154000
Q4
Time: Which of the times in the following list are closest to hour 811836 since 1970/01/01 01:00:00?
O 2062/07/17 08:06:40
O 2062/07/19 20:41:57
O 2062/08/25 01:23:54
2062/08/12 13:38:34
2062/08/16 14:02:27
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 4 steps with 7 images

Knowledge Booster
Similar questions
- Here's some background information on our Gregorian calendar. Although the Gregoriancalendar was created in 1582, The United States did not adopt it until 1752. Therefore, theGregorian calendar formula for calculating leap years only applies to years 1752 and later in theUnited States. The Gregorian calendar provided an improved formula for calculating whichyears are Leap Years. The criteria for a determining whether a year is a Leap Year is:Leap Year Definition:• The year is evenly divisible by 4; • If the year can be evenly divided by 100, it is NOT a leap year, unless;• The year is also evenly divisible by 400. Then it is a leap year.Your assignment is to create a Python program that in general uses a function to determinewhether a year is a leap year and another function for obtaining year input values from the user.More specifically your program should:1. Contain a function that determines whether a year passed to it is:a. A valid year for the Gregorian calendar usage in the…arrow_forwardEngineers use both English and SI (Système International d’Unités) units on a regular basis. Some fields use primarily one or the other, but many combine the two systems. For example, the rate of energy input to a steam power plant from burning fossil fuels is usually measured in Btu/hour. However, the electricity produced by the same plant is usually measured in joules/s (watts). Automobile engines, by contrast, are often rated in horsepower or in ft lbf/s. Here are some conversion factors relating these different power measurements: a) Generate a table of conversions from kW to hp. The table should start at 0 kW and end at 15 kW. Use the input function to let the user define the increment between table entries. Use disp and fprintf to create a table with a title, column headings, and appropriate spacing. The output should look like: kW hP 0.0 0.00 2.5 3.35 5.0. 6.70 7.5 10.06 10.0 13.41 12.5…arrow_forwardusing c_compilerarrow_forward
- what is the correct formula to solve thisarrow_forwardOur everyday number system in the UK and many other parts of the world is a base-10 system using Arabic numerals, namely the digits 0, 1, 9. Integers larger than 9 are represented by sequences of these elementary numerals. The numerical value encoded by such a sequence is determined by multiplying each numeral by 10k, where k is the position of the numeral counted from the back and starting at zero, and then summing together the contributions from all numerals. For example, 5207 = 5 × 10³ +2×10² +0×10¹ + 7×10⁰ The built-in int function in Python can take a string (type str) representing such a number and convert it to a Python integer (type int). Write a similar function base14_convert that takes a string and converts it to a Python integer according to the following number system: • the base is 14, i.e., the individual digits have to be multiplied by powers of 14 to obtain the numerical value; digits are represented by lower-case letters 'a', 'b', 'c', 'd', ..., i.e., 'a' is…arrow_forwardComputer Science Please answer the questions. It is either yes or no for the answers.arrow_forward
- The "e" number is an important constant real number in mathematics and engineering science.It's definition of natural logarithm and also an irrational number.Approximate value is e=2.718281828459045235360287471352662497757247.....In the following equation which discovered by Harlan A. Brothers and John A. Knox, the greater the number "x", the result approximates the actual number "e".((2x+1)/(2x-1))^x Code a "C" program to calculate the approximate value of "e" by increasing the value of "x" (x=1, x=2, x=3...)Let the value of "x" continue to increase (if the difference is bigger) until the difference between the results from the equations and value 2.718281 is less than 0.000001.When the difference is less than 0.000001, project the x value at that moment and the result obtained from the equation on the screen.arrow_forwardDraw out a TM (computable function) that does the following: - Input: Two binary string of equal length separated by # (example: 0110#1010) - Output: The result from performing logical AND on the two binary strings (0010). You may write the output on Tape 2.arrow_forwardWith a fancy calculator, finding square roots is easy. But what if you only had a basic four-function calculator? Assuming that number holds the value that you want to calculate the square root of, the following algorithm approximates the square root of a number: Get a guess from a human Square the guess If the squared guess is within 0.1 of the original number, we will accept the guess as our answer If it is not, try again with a different guess and keep trying until we get an answer that is close enough This algorithm relies on a human to make the guesses, though it wouldn't be too hard to also design an algorithm for making an appropriate guess. What would be a flowchart for this?arrow_forward
- Computer Science- AI- NLP - You are given a training set of 30 numbers that consists of 21 zeros and 1 each of the other digits 1-9. Now we see the following test set: 0 0 0 0 0 3 0 0 0 0. What is the unigram perplexity?arrow_forwardUsing Python or awk script and any given text file such as a book find: (A) the number of unique words,(B) the ten most and least frequently used words,(C) the top five frequently used five-letter words,(D) the top five frequently used six-letter words,(E) the top five frequently used words with seven or more letters,(F ) the average number of words between each word with seven or more letters (and the standard deviation)arrow_forwardWrite a Python program that implements the Taylor series expansion of the function (1+x) for any x in the interval (-1,1], as given by: 1(1+x) = x-x²/2 + x³/3 - x^/4 + x³/5. The program prompts the user to enter the number of terms n. If n> 0, the program prompts the user to enter the value of x. If the value of xis in the interval (-1, 1], the program calculates the approximation to l(1+x) using the first n terms of the above series. The program prints the approximate value. Note that the program should validate the user input for different values. If an invalid value is entered, the program should output an appropriate error messages and loops as long as the input is not valid. Sample program run: Enter number of terms: 0 Error: Zero or negative number of terms not accepted Enter the number of terms: 9000 Enter the value of x in the interval (-1, 1]: -2 Error: Invalid value for x Enter the value of x in the interval (-1, 1]: 0.5 The approximate value of ln (1+0.5000) up to 9000 terms…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY