CP4P_NumberSystems_Activity_Answers

docx

School

Seneca College *

*We aren’t endorsed by this school

Course

COMPUTER F

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by UltraStraw12009

Report
Number Systems Activity Computer Principles for Programmers Md Tahmid Kabir Sowdagor 168400224 mtksowdagor @mySeneca.ca Click or tap here to enter text. There are many notes in the instructions to help you earn marks for the questions below. Exercise One of Two integer overflow (80 points) 1. (5 points) Using your student number as the number of seconds , how many days will it take until that value is reached? (to two decimal places) Number of days = Number of seconds / (60 seconds/minute * 60 minutes/hour * 24 hours/day) Number of days = 168400224 / (60 * 60 * 24) =1948.15 days 2. (20 points) Using your student number as the number of seconds , how much time would that represent? Years = 168400224 seconds / 31,536,000 seconds/year = 5.33 years Days = (0.33 years) * 365.25 days/year =121.20 days Hours = (0.20 days) * 24 hours/day = 4.80 hours Minutes = (0.80 hours) * 60 minutes/hour = 48 minutes Seconds = 0.00 seconds Because I converted the entire number. 5 121 4 48 0 YEARS DAYS HOURS MINUTES SECONDS FALL 2023 WEEK 4 1 of 4
Number Systems Activity Computer Principles for Programmers 3. (5 points) What are the maximum and minimum values that can be stored in a short 16- bit signed integer? 16-bit signed integer maximum = 32,767 Minimum -32,768. 4. (5 points) Give examples of two short 16-bit signed integers that when added together would cause overflow. 32797 + 32767 are two positive values causing overflow when added together. -32768 + -32768 are two negative values causing overflow when added together. Binary Search Bug 5) (10 points) What is potentially wrong with the (low + high) / 2 calculation to find the middle point? Under what conditions would the calculation go wrong? It can cause overflow and lead to incorrect results. if low and high are large positive integers it can add them to exceed the maximum value represented by the integer data type. IF low and high are very different in magnitude with floating-point numbers then the calculation goes wrong. 6) (10 points) REWRITE the mid calculation to prevent overflow from mid = (low + high) / 2; to mid = (low / 2) + (high / 2) + ((low % 2 + high % 2) / 2); 7) (25 points) Write a 250+ word “reflection”(similar to a workshop in your programming class) describing the steps you used to develop and test your solution to the calculation bug. The first critical step was correctly identifying the problem. My calculation frequently generated incorrect results, suggesting a problem in my code. I went over the code and found the accurate calculation which caused problems. After identifying the error in calculations, I focused on separating it from the rest of the code. This meant commenting out other parts of the code to ensure that the problem was actually limited to the reported calculating. Thirdly I did a code inspection. I investigated the code relating to the calculation problem in great depth. I took a look for syntax and logical errors plus erroneous variable values. I also FALL 2023 WEEK 4 2 of 4
Number Systems Activity Computer Principles for Programmers went over the proper documentation and compared my code with samples to make sure that it was correct. I used debugging tools and techniques in my programming platform to help in the debugging process. Setting breakpoints, checking variable values, and using print statements to navigate the development of the code. After developing all the tools and codes I did the testing part. I did testing to avoid the introduction of new issues while resolving the calculation issue. This entailed retesting previously working pieces of the code to ensure that they continued to perform properly after my changes. Finally, I documented the entire debugging and testing process. Exercise Two of Two Numbering Systems and Conversions (20 points) 8) (5 points ) Fill in this chart as per the column headings Red decimal Green decimal Blue decimal Hex triplet 192 255 238 #C0FFEE 126 164 112 #7EA470 186 187 30 #BABB1E 208 13 30 #D00D1E 15 245 231 #0FF5E7 9) (15 points) Fill in this chart as per the column headings Hex triplet Red decimal Green decimal Blue decimal Change each row's Font or Shading colour to match the RGB value FALL 2023 WEEK 4 3 of 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Number Systems Activity Computer Principles for Programmers #3A26F2 58 38 242 Font or Shading colour matches RGB #844D42 132 77 66 Font or Shading colour matches RGB #094353 9 67 83 Font or Shading colour matches RGB #7D6CB7 125 108 183 Font or Shading colour matches RGB FALL 2023 WEEK 4 4 of 4