CS 100 Spring Lecture Notes 3/8/05 Review for Exam 2

Similar documents
1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

1. The Normal Distribution, continued

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Data Representation From 0s and 1s to images CPSC 101

Hexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?

Memory Addressing, Binary, and Hexadecimal Review

Spring CS Homework 3 p. 1. CS Homework 3

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Introduction to Computer Science (I1100) Data Storage

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

Objectives. Connecting with Computer Science 2

Module 1: Information Representation I -- Number Systems

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College September 6, 2018

Variables and Data Representation

Pick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1

Signed umbers. Sign/Magnitude otation

RENDERING TECHNIQUES

2. INTRODUCTORY EXCEL

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Year 10 OCR GCSE Computer Science (9-1)

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

Advanced Techniques. Criterion E: Product development. Three or more related tables. Complex queries / Calculated fields. Use of graphics fields

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Data Representation 1

Bits, bytes, binary numbers, and the representation of information

GCSE Computer Science Component 02

Colour and Number Representation. From Hex to Binary and Back. Colour and Number Representation. Colour and Number Representation

Discussion. Why do we use Base 10?

Chapter 2 Bits, Data Types, and Operations

(Refer Slide Time: 01.26)

Starting Boolean Algebra

Lecture 1. Course Overview Types & Expressions

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Maths Mastery Curriculum. Adapted from The White Rose Hub Maths Curriculum

Unit 2 Digital Information. Chapter 1 Study Guide

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

UNIT 7A Data Representation: Numbers and Text. Digital Data

GENERAL MATH FOR PASSING

Advanced Computer Architecture-CS501

Floating Point Arithmetic

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CSC201, SECTION 002, Fall 2000: Homework Assignment #2

Binary. Hexadecimal BINARY CODED DECIMAL

Binary, Hexadecimal and Octal number system

Admin CS41B MACHINE. Midterm topics. Admin 2/11/16. Midterm next Thursday in-class (2/18) SML. recursion. math. David Kauchak CS 52 Spring 2016

CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm

Wednesday, February 4, Chapter 4

IMAGE COMPRESSION USING FOURIER TRANSFORMS

Number System. Introduction. Decimal Numbers

MAT 003 Brian Killough s Instructor Notes Saint Leo University

ROUNDING ERRORS LAB 1. OBJECTIVE 2. INTRODUCTION

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra

Bits and Bit Patterns

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters.

Switching Circuits and Logic Design Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Mastering Binary Math

CS152 Computer Architecture and Engineering CS252 Graduate Computer Architecture Spring Caches and the Memory Hierarchy

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

CS101 Lecture 04: Binary Arithmetic

Example 1: Denary = 1. Answer: Binary = (1 * 1) = 1. Example 2: Denary = 3. Answer: Binary = (1 * 1) + (2 * 1) = 3

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Lecture 2: Number Systems

Switching to AQA from Edexcel

(Refer Slide Time 3:31)

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

OCR J276 GCSE Computer Science

Final Labs and Tutors

CSE 410 Computer Systems. Hal Perkins Spring 2010 Lecture 12 More About Caches

N.B. These pastpapers may rely on the knowledge gained from the previous chapters.

Chapter 1. Data Storage Pearson Addison-Wesley. All rights reserved

Problem 1: Binary, Decimal, and Hex Number Representations [6 marks]

Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

The type of all data used in a C++ program must be specified

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Data Storage. Slides derived from those available on the web site of the book: Computer Science: An Overview, 11 th Edition, by J.

CS & IT Conversions. Magnitude 10,000 1,

Where are we? Compiler. translating source code (C or Java) Programs to assembly language And linking your code to Library code

Lecture 2: Number Representa2on

Chapter 1 Emad Felemban

Chapter 1 Review of Number Systems

Read this before starting!

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Unit 6 Quadratic Functions

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

What Is It? Instruction Register Address Register Data Register

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

Admin. ! Assignment 3. ! due Monday at 11:59pm! one small error in 5b (fast division) that s been fixed. ! Midterm next Thursday in-class (10/1)

3 Data Storage 3.1. Foundations of Computer Science Cengage Learning

Part I Anton Gerdelan

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

ASYMPTOTIC COMPLEXITY

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Reviewing all Topics this term

Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9 Week 10 Week 11 Week 12 Week 13 Week14. Number- addition subtraction,

Chapter 9: A Closer Look at System Hardware

Transcription:

CS 100 Spring 2005 Lecture Notes 3/8/05 Review for Exam 2 The second exam is Thursday, March 10. It will cover topics from Homework 2 through Homework 4, including anything pertaining to binary representation. Anything covered in lecture on the topics covered in Homework 2 -Homework 4 is fair game. Main Test Topics hexadecimal number system binary-arithmetic overflow cache access time questions Graphics (how graphics are stored in the computer) Networks: definitions modem speed questions Web/Internet Hexadecimal: Hexadecimal is base 16 There are 3 types of problems involving hexadecimal (hex) that you should be able to do: - convert decimal to hexadecimal - convert hex to decimal - convert binary to hex Converting Hexadecimal to Decimal: First we learned how to convert hexadecimal to decimal. Recall that each position in a hexadecimal number represents a multiple of a power of 16: 256 16 2 16 0 Example 1: Convert 100 (hexadecimal) to decimal: 1 0 0 = 1*256 + 0*16 + 0*1 = 256 256 Example 2: Convert 22 (hexadecimal) to decimal: 22= 2 * 16 + 2 * 1 = 32 + 2 = 34 In hexadecimal we need to represent the values 10,11,..., 15 as single digits so we use letters: A=10

B=11 C=12 D=13 E=14 F=15 Example 3: Convert 2C (hex) to decimal: Recall that C represents 12, so 2C= 2 * 16 + 12 * 1 = 32 + 12 = 44 Converting Decimal to Hexadecimal: This is trickier. I suggest you do it as follows: Say you want to convert 50 (decimal) to hexadecimal. Ask yourself: 1) What is the largest power of 16 that goes into this number? For our example of 50, the answer is 16. Draw slots for 1, 16. 2) Figure out: How many times does this power go into this number? For our example,how many times does 16 go into 50? Answer: 3. 3) Put that value in the correct position. Example: 3 Repeat steps 1-3 with the remainder until the remainder is 0. In our example the remainder of 50/16 is 2 since 3*16 = 48. Since 2 < 16, we can put 2 in the 1's position giving: 32 as our answer. 50 10 = 32 16 Example 1: Convert 6610 to hexadecimal (the 10 means that this number is base 10). The largest power of 16 that goes into 66 is again 16 (256 doesn't go). How many times does 16 go into 66? Answer: 4. 4*16 = 64. So we put a 4 in the 16 position and the remainder (2) in the 1's position: 66 = _4 2_ So 66 10 = 42 16 Example 2: Convert 17010 to hexadecimal. 16 is the largest power of 16 that goes into 170. It goes 10 times. We use A to represent 10, so we put an A in the 16 position. What is the remainder? 170 = 10*16 + 10 so the remainder is 10 and the answer is AA. 170 = _A_A Check the answer to see if it is correct: 170=10*16+10

Convert 8 bit binary to Hexadecimal: Given an 8-bit binary string, what is the equivalent value in hexadecimal? You could calculate this by converting the binary to decimal and then converting the decimal to hexadecimal. There is an easier way - a trick. How (roughly): 1) Divide the bits into groups of 4 bits. 2) Calculate the decimal equivalent of each group of 4 bits. Put the hexadecimal character for that decimal number in the position under the 4 bits. Example 1: Convert 11100110 to hexadecimal. Given: 11100110 Divide into 2 groups: 1101 0110 The first group, 1101 = 8 + 4 + 1 = 13, which is D in hexadecimal. The second group 0110 = 4 + 2 = 6 in hexadecimal. So 11010110 = D6 in hexadecimal. Example 2: Write 10011111 as hexadecimal. 10011111 = 1001 1111; 1001 = 9 1111 = 15, which is represented in hex as F. So the answer is 9F. Example 3: Write 00001111 in hexadecimal. First divide into 2 groups: 0000 1111. We know 0000 = 0 and 1111 = F so the answer is 0F. Arithmetic overflow When you are doing math using almost any kind of machine (like a calculator or a computer) there is a limited amount of storage for any number. Where I could continue writing 0's after a number to make it longer in real life, a computer just has a certain number of bits to hold any number. Imagine a calculator that only had 3 spaces to hold decimal digits. If you tried to add 900 and 100, both of which just take 3 spaces, then you would get 1000, which takes 4 spaces. If there was only room for 3 spaces, then you would likely lose the 1 in 1000, giving a wrong answer. So arithmetic overflow occurs when a program tries to store a value in a memory cell that is too large for the memory cell. This can lead to serious numeric errors. For example, if you have 8 bits to store a positive unsigned integer, then the largest value you can store is: 11111111 which is 255 in decimal. Any number 255 or smaller can be stored successfully in 8 bits. But what if you try to add two of these numbers? In some cases will you have a problem? What if you try to add 100 and 200? You can represent both of these numbers in binary in 8 bits, but when you add them you get 300 which is too big for 8 bits and you would lose any bits above the 8th bit and get a wrong answer. Possible Questions:

If you have 8 bits which of these additions will produce an overflow? 10+20 100+100 200+300 200+60 100+100 Answer: 200+300 and 200+60 Cache Access Time Recall what cache is and how we use it. It is a small amount of fast memory used to help speed up accesses to memory. When we only had RAM, it was easy to say how long it took to access memory - it was whatever the speed of RAM was. When we are using cache, it is more complicated. Assume you are using a cache and want to access something in memory. Instead of going straight to RAM to get it, you first check cache to see if it is there. If so, good - return the value. If not, go to RAM to get the value. We can't calculate the exact time to access data now, because it depends on an unknown - whether the data is in cache or not. But we can compute the average (or expected) cache access time if we know the following data: the cache access time, the RAM access time, and the hit rate. The hit rate is the percentage of time that the data that we are looking for is in cache. You can express it as a percent, like 70%, but when you calculate with it you must express it as a decimal like 0.7. A miss is the opposite of a hit - it is when the data we wanted was not in cache. Since every memory access is either a hit or a miss, we have: miss rate = 1 - hit rate How should we calculate the average cache access time? We use the following formula: Avg access time with cache = (time for a hit)*hit rate + (time for a miss)* miss rate The time for a hit = the time to access cache, which will usually be given to you in the question. What is the time for a miss? Since we have to check cache first to see if the data is in there, the time for a miss is (cache access time + RAM access time). So the formula is: Average access time= (time_to_access_cache )* hit rate + (time_to_access cache + time_to access_ram) * miss rate and you just plug into this formula. Example: Homework 2, Problem 5: RAM access time=40ns Cache access time =10ns Hit rate=60% Plugging into the formula: Avg. Access Time = 10 * 0.6 + (10 + 40) * 0.4 = 6 + 20 = 26 ns.

In these problems we will either give you the values (cache time, RAM time, hit rate) or could make you calculate one from another. What if we said the cache access time is 10 ns and RAM is 3 times slower than cache. Then you should be able to figure out that the RAM access time should be 3*10 = 30ns. Representing Graphics 2 main formats bitmap--pixels vector--equations, scalable Within bitmaps there are different file formats like Jpeg and GIF. Both of these are compression algorithms. A file with a name like mypicture.jpeg is likely to have been compressed. Problems: On the homework, to test your understanding of how graphics can be stored, we asked questions like the following: Question: Suppose you have a 10x10 picture. If the picture is black and white, where black is represented by a 1 and whte by a 0, how much storage does this take (in bytes)? Answer: Each pixel takes 1 bit (to store a 0 or a 1). The 10x10 image has 100 pixels, 100 pixels * 1 bit per pixel = 100 bits. But we wanted the answer in bytes so we have to divide 100 bits/8 = 12.5 bytes. A better answer would be 13 bytes - round up. Question: Same situation, but now we want to store greyscale 0-255. Now each pixel needs 1 byte storage so a 10x10 picture has 100 pixels & 100 bytes Question: Suppose you still have a 10X10 picture, but now you want to store one of 16 colors with each pixel. If each color has a number between 0 an 15, then you need 4 bits to store the color numbers (0000 to 1111). This is half a byte. So with 16 colors each pixel needs 1/2 byte storage. A 10x10 epicure has 100 pixels &, therefore, 50 bytes Question: If you wanted to use TrueColor, then you store a red, green, and blue byte with each pixel. So each pixel needs 3 bytes of storage. For a 10X10 picture, this would take 300 bytes. JPEG, GIF are compressed file formats for bitmaps