A Level Computing Component 2

Slides:



Advertisements
Similar presentations
Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Advertisements

Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Topic 4 Computer Mathematics and Logic
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Simple Data Type Representation and conversion of numbers
Numbers and number systems
Data Representation – Binary Numbers
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
IT253: Computer Organization
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Floating Point Arithmetic
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
 Lecture 2 Processor Organization  Control needs to have the  Ability to fetch instructions from memory  Logic and means to control instruction sequencing.
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
PHY 201 (Blum)1 Shift registers and Floating Point Numbers Chapter 11 in Tokheim.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
PHY 201 (Blum)1 Shift registers and Floating Point Numbers Chapter 11 in Tokheim.
Learning Objectives 3.3.1f - Describe the nature and uses of floating point form 3.3.1h - Convert a real number to floating point form Learn how to normalise.
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
CHAPTER 5: Representing Numerical Data
Floating Point Numbers
Floating Point. Binary Fractions.
Lesson Objectives Aims You should know about: Binary numbers ‘n’ that.
Floating Point Numbers
Floating Point Representations
Department of Computer Science Georgia State University
Objectives Today: P4 Data Types – Floating Points P4 Variable Quiz P3 Iteration and Selection Practical Are you logged on? Then come around the table Unit.
Cosc 2150: Computer Organization
Binary, Denary, Hexadecimal Conversion Binary Addition
A brief comparison of integer and double representation
Chapter 4 Operations on Bits.
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
Chapter 3 Data Storage.
Solutions Chapter 3.
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Shift registers and Floating Point Numbers
Data Representation Data Types Complements Fixed Point Representation
Dr. Clincy Professor of CS
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Dr. Clincy Professor of CS
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Storing Negative Integers
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Computer Organization
Representation of real numbers
23/04/2019 Data Representation Conversion.
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
Floating Point Numbers
Shift registers and Floating Point Numbers
Chapter3 Fixed Point Representation
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
1.6) Storing Integer: 1.7) storing fraction:
ID1050– Quantitative & Qualitative Reasoning
Two’s Complement & Binary Arithmetic
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

A Level Computing Component 2 3M, N, O

Assessment Outcomes 3M (A2) Explain and use shift functions: logical and arithmetic shifts. 3N (A2) Interpret and apply shifts in algorithms and programs. 3O (A2) Describe the causes of overflow and underflow.

Shift Functions 1 Shift Left 3 Shift Right 0000 1111 = 15 A  shift function moves bits to the left or the right. If the bits are shifted to the left, the left-most bit drops away and a zero is added to the right-most bit. If the bits are shifted to the right, then the right-most bit drops away and a zero is added to the left-most bit. 1 Shift Left 3 Shift Right 0000 1111 = 15 A Left shift of 1 would move everything 1 to the left: 0001 1110 = 30 0000 1111 = 15 A Right shift of 3 moves everything to the right 0000 0001 = 1

Uses of Shift Functions Run the following code in Python: x = 15 print ('x is', x) print ('x shifted one place to the left is', x << 1) print ('x shifted two places to the left is', x << 2) print ('x shifted three places to the left is', x << 3) print ('x shifted four places to the left is', x << 4) x = 15 print ('x is', x) print ('x shifted one place to the left is', x >> 1) print ('x shifted two places to the left is', x >> 2) print ('x shifted three places to the left is', x >> 3) print ('x shifted four places to the left is', x >> 4)

Use of shift functions Did you notice a pattern when you shifted bits to the left? You should have seen that the original number was multiplied by two with each bit shift to the left. Moving the bits to the right is the same as dividing by two, although you can see the problem with rounding that occurred..

Uses of Shift Functions – Logical Operations AND OR 35 AND 2 written in binary is: 0010 0011 AND 0000 0010 print ('35 AND 2 is 0010 0011 AND 0000 0010 = ', 35 & 2) Where a bit is 1 in both binary numbers it will become a 1 in the output.. 0010 0011 0000 0010 38 OR 19 written in binary is: 0010 0110 OR 0001 0011 print ('38 OR 19 is 0010 0110 OR 0001 0011 = ', 38 | 19) Where a bit is 1 in One or the Other binary number it will become a 1 in the output.. 0010 0110 0001 0011 0011 0111

Uses of Shift Functions – Logical Operations XOR NOT 38 XOR 19 in binary is written 0010 0110 XOR 0001 0011 print ('38 XOR 19 is 0010 0110 XOR 0001 0011 = ', 38 ^ 19) 0010 0110 0001 0011 0011 0101 You can find the complement of a number by using a NOT operation. For example the complement of 60: 0011 1100 1100 0011 (using 2s complement)

3N Exercises Complete the 3N exercises to apply arithmetic shifts and logical operations.

3O - Interpret and apply shifts in algorithms and programs. Overflow and underflow are general terms. They describe the situation when something becomes too big or too small to be processed correctly or stored in the space allocated to it correctly. If you have a fixed-size data structure such as a stack that has been set up to hold twenty data items, and you try to add a twenty first data item, this will cause a 'stack overflow' error. This is because the data structure is not big enough to hold the extra piece of data you are trying to add to it. 

Overflows – 8 Bit Binary Imagine you are trying to add two 8-bit numbers in an 8-bit computer. The largest number that a register or memory location can hold is 8 bits. What happens when you add these two numbers?     1 1 1 1 0 0 0 0   + 1 0 0 1 0 0 0 0  The answer is: 1 1 0 0 0 0 0 0 0 This of course has 9 bits! As our memory locations can only hold 8 bits, that extra bit on the far left causes an 'overflow' error. This signals that the result was too big to hold in 8 bits. The sum we just did was 240 + 144, which equals 384. The largest number that 8 bits can hold is 1111 1111 or 255 so having an overflow error makes sense with this calculation. 

Overflows – Floating Point Going back to decimal numbers for a moment, you can represent a number in scientific notation as follows The first part is called the 'mantissa'. The mantissa also holds the sign of the number. The second part is called the 'exponent' and it defines where the decimal point needs to be if the number is shown in its standard decimal form. In this case it indicates that this number is to be multiplied by a thousand and so the decimal point moves 3 locations to the right, like this -2344.5 Binary floating point uses the same idea. A binary floating point number is in two parts. The Mantissa and the Exponent. Both the mantissa and the exponent is in twos complement format. So if there is a 1 present in the leftmost bit of the mantissa, then this is a negative binary number. The exponent part is indicating where the decimal point needs to be.

Floating Point Let's break down this particular number and see what it represents. 1.001 mantissa. The most significant bit is a 1 and we know it is in two's complement so this must be a negative number. 0010 exponent. This indicates how many places the the decimal point needs to move. If it is a positive exponent, then you move the decimal point to the right. If it was a negative exponent, then you would slide the decimal point to the left. The exponent is 0010, so this is a positive 2. Slide the decimal point of the mantissa 2 positions to the right. So the full binary number is 1.001 becomes 100.1 It is in two complement and it is a negative number so flip the bits to the left of the last 1 011.1 The number is -3.5 decimal

Floating Point OverFlows Because the highest exponent is 15 in 4 bits it can easily create an overflow. If there needed to be more than 15 shifts then there would be an exponent overflow.

Underflows The smallest positive number we can hold is when the mantissa is the smallest positive number and the exponent is the largest negative number. The smallest positive (normalised) mantissa is 01000 and the largest negative exponent is 100 (-4 as a 2s complement number). The smallest positive number we can hold is therefore 0.03125 Programs respond to underflow conditions in different ways. Some report an error, while others approximate as best they can and continue processing. For example, if your computer supports eight decimal places of precision and a calculation produces the number 0.000000005 (with nine decimal places), an underflow condition occurs.

3O Exercises Explain the different types of Overflow using examples Explain how an underflow occurs when a computer is trying to store a small value Explain how an underflow can occur when a computer is trying to store a number with too fine accuracy