CSCI N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science The Switch, Part 2.

Slides:



Advertisements
Similar presentations
DATA REPRESENTATION Y. Colette Lemard February
Advertisements

COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.
Floating Point Numbers
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
Binary Arithmetic Math For Computers.
Number Systems Lecture 02.
Binary Number Systems.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
The Binary Number System
Data Representation Number Systems.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Chapter 3 Number Representation. Convert a number from decimal 、 hexadecimal,octal to binary notation and vice versa. Understand the different representations.
Numeral Systems Subjects: Numeral System Positional systems Decimal
Computer Arithmetic Nizamettin AYDIN
CSCI N301: Fundamental Computer Science Concepts Copyright ©2006  Department of Computer & Information Science The Switch, Part One.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
Lecture Overview Introduction Positional Numbering System
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Number systems, Operations, and Codes
CSC 221 Computer Organization and Assembly Language
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Introduction to Number System
THE BINARY SYSTEM.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Number Systems and Binary Math
Dividing Decimals # ÷ 3.5 next Taking the Fear out of Math
Computer Organization and Design Information Encoding II Montek Singh Wed, Aug 29, 2012 Lecture 3.
Significant Figure Rules RulesExamples The following are always significant Non zero digits Zeros between non zero digits Zero to the right of a non zero.
Number Systems & Operations
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Introduction To Number Systems Binary System M. AL-Towaileb1.
Number Systems and Computer Arithmetic Winter 2014 COMP 1380 Discrete Structures I Computing Science Thompson Rivers University.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Binary & Normalization What is Normalization? We discussed this the other day (special review session slides, near the end) Can someone tell us.
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.
Scientific Notation Notes Physical Science (Freshman Physics)
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Floating Point Representations
Department of Computer Science Georgia State University
Unit 1 Introduction Number Systems and Conversion.
Number Systems and Binary Arithmetic
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Scientific Notation.
COMPUTING FUNDAMENTALS
Data Structures Mohammed Thajeel To the second year students
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Digital Logic & Design Lecture 02.
Number Representation
Binary to Decimal Conversion
Introduction To Number Systems
Presentation transcript:

CSCI N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science The Switch, Part 2

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Goals By the end of this unit, you should understand … How to perform binary addition and subtractionHow to perform binary addition and subtraction How computers represent signed numbers (positive and negative)How computers represent signed numbers (positive and negative) How to use Twos ComplementHow to use Twos Complement How to represent a number using Scientific Notation.How to represent a number using Scientific Notation.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Review The engineering decision to use simple, two-state switches to build computers forced computers to “think” in binary.The engineering decision to use simple, two-state switches to build computers forced computers to “think” in binary. How do we convert to and from binary?How do we convert to and from binary? What about octal?What about octal? What about hexadecimal?What about hexadecimal?

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Arithmetic Computer processing requires a little more capability in binary math, notably arithmetic.Computer processing requires a little more capability in binary math, notably arithmetic. Let’s consider addition and subtraction …Let’s consider addition and subtraction …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Addition Just a few combinations are possible:Just a few combinations are possible: – = 0 2 – = 1 2 – = 1 2 What about ?What about ?

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Addition = 10 2 Remember what that 10 means: it means a zero in the right column, and a one in the left columnRemember what that 10 means: it means a zero in the right column, and a one in the left column When you carry in base two, you are bringing a power of two to the left…When you carry in base two, you are bringing a power of two to the left…

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Addition =14 10 =11 10 =25 10

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Subtraction Subtraction in base two is similar to additionSubtraction in base two is similar to addition –11 2 – 11 2 = 00 2 –11 2 – 00 2 = 11 2 –10 2 – 00 2 = 10 2 What about ?What about ?

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Addition = 1 2 Think about borrowing in decimal – you are really borrowing a power of your base …Think about borrowing in decimal – you are really borrowing a power of your base … In Base-10, we borrow 10 from the left column and give it to the next column to the right. So …In Base-10, we borrow 10 from the left column and give it to the next column to the right. So … In Base-2, we borrow 2 from the left column and give it to the next column to the right.In Base-2, we borrow 2 from the left column and give it to the next column to the right.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Addition =51 10 =22 10 =29 10

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Borrowing: A Little Trick Many students find it convenient to just mentally convert the binary number to decimal, complete the subtraction, and then convert the answer back to binary.Many students find it convenient to just mentally convert the binary number to decimal, complete the subtraction, and then convert the answer back to binary. Consider 10 2 – 1 2 = ?Consider 10 2 – 1 2 = ? –A one in binary is still a one in decimal –When you borrow for the zero, you bring over a power of two, which is equal to two –The decimal conversion for the borrowing is 2-1, which is 1 –And 1 10 = 1 2 Be sure to add your answer back up as a checkBe sure to add your answer back up as a check

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Negative Numbers We have mastered binary math for positive integersWe have mastered binary math for positive integers But what about negative numbers?But what about negative numbers? Handling the negative sign has proven somewhat problematic, as we will see …Handling the negative sign has proven somewhat problematic, as we will see …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Negative Integers: Sign/Magnitude Notation The first solution for encoding negative numbers in binary form was to dedicate a switch (which we now know is a memory location) to communicate whether a number was positive or negativeThe first solution for encoding negative numbers in binary form was to dedicate a switch (which we now know is a memory location) to communicate whether a number was positive or negative The only thing required was to agree, in the bank of switches representing the number, which switch referred to the signThe only thing required was to agree, in the bank of switches representing the number, which switch referred to the sign In one of the more popular encoding notations for negative numbers, the first switch is the sign.In one of the more popular encoding notations for negative numbers, the first switch is the sign.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Negative Integers: Sign/Magnitude Notation A 0 setting means the number is positive, a 1 setting means the number is negative.A 0 setting means the number is positive, a 1 setting means the number is negative. This encoding scheme (for signed integers) is called sign/magnitude notation.This encoding scheme (for signed integers) is called sign/magnitude notation. The first switch is the sign, the remaining switches represent the binary magnitude of the number.The first switch is the sign, the remaining switches represent the binary magnitude of the number. Which highlights one of our key concepts about binary encoding – the leftmost digit could be a negative sign, or a “one” in magnitudeWhich highlights one of our key concepts about binary encoding – the leftmost digit could be a negative sign, or a “one” in magnitude The computer must be told which interpretation/decoding scheme to useThe computer must be told which interpretation/decoding scheme to use

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Sign/Magnitude: The Problem What was wrong with this scheme?What was wrong with this scheme? –Great for all numbers except 0 … –This encoding scheme allows you to come up with 2 distinct encoding schemes for 0, one with a positive sign, and one with the negative sign –The one with the negative sign has no mathematical meaning, and the ambiguity of two patterns representing the same number is problematic. So, most computers use a different scheme than sign/magnitude for representing negative integers …So, most computers use a different scheme than sign/magnitude for representing negative integers …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Twos Complement Twos Complement solves the ambiguity problem.Twos Complement solves the ambiguity problem. The scheme works because we are in binary math, which has only 2 digits.The scheme works because we are in binary math, which has only 2 digits. Offsetting one moves you to the only other possible digit, etc.Offsetting one moves you to the only other possible digit, etc.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Twos Complement In Twos Complement, you encode positive integers normally.In Twos Complement, you encode positive integers normally. To use Twos Complement for negatives:To use Twos Complement for negatives: –Complement every digit in the number (change 1s to 0s and 0s to 1s) –Add 1 to the complemented number Example: –101 = = 011Example: –101 = = 011

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Twos Complement: Math Twos Complement allows us to add the representation and processing of negative integers to our growing computing capability.Twos Complement allows us to add the representation and processing of negative integers to our growing computing capability. To add a positive and negative number, first perform the twos complement trick on the negative number, and then add normally.To add a positive and negative number, first perform the twos complement trick on the negative number, and then add normally. To add two negative numbers, first encode both of them in 2’s complement, and then add normally.To add two negative numbers, first encode both of them in 2’s complement, and then add normally.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science What about fractional values? Our goal is to learn how to encode all numbers in a way that they can be represented using switch settingsOur goal is to learn how to encode all numbers in a way that they can be represented using switch settings –We can encode positive integers –We can encode negative integers But what about decimal numbers (numbers with fractional values)?But what about decimal numbers (numbers with fractional values)? To store decimal numbers, most computers utilize scientific notation …To store decimal numbers, most computers utilize scientific notation …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Math and Scientific Notation As a civilization, we now work with numbers so big and so small that mathematicians have already had to wrestle with creating a manageable notation.As a civilization, we now work with numbers so big and so small that mathematicians have already had to wrestle with creating a manageable notation. Scientists developed scientific notation as a standard way to represent numbers.Scientists developed scientific notation as a standard way to represent numbers.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Binary Math and Scientific Notation Consider the following example: +/ * 10 +/- 23Consider the following example: +/ * 10 +/- 23 The part is the mantissa.The part is the mantissa. The 10 part is the base.The 10 part is the base. The 23 part is the exponent.The 23 part is the exponent.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Scientific Notation Let’s move up a level of abstraction to the more generalized case of scientific notation:Let’s move up a level of abstraction to the more generalized case of scientific notation: +/- M * B +/-E –M is the mantissa. –B is the base. –E is the exponent. –+/- means the number can be positive or negative.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Switch Math: the Holes If we can figure out how to use scientific notation to encode base ten decimal numbers in a binary form of scientific notation, we can represent any finite number in our computer and our switch math will be complete …If we can figure out how to use scientific notation to encode base ten decimal numbers in a binary form of scientific notation, we can represent any finite number in our computer and our switch math will be complete …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Interpreting Scientific Notation It turns out that handling scientific notation, or any other encoding scheme, is amazingly simpleIt turns out that handling scientific notation, or any other encoding scheme, is amazingly simple –We design the computer to know which interpretation scheme to use! –We will just figure out how to program in some logic that says “if a number is tagged as being in scientific notation, just use a look up chart to interpret the number.”

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Interpreting Scientific Notation Given an encoded number, to decode it such that it is in scientific notation, you would need to know several things –Given an encoded number, to decode it such that it is in scientific notation, you would need to know several things – –How big is the overall memory allocation (how many switches were used)? –How many switches are dedicated to the mantissa, and which are they? –How many switches are dedicated to the exponent, and which are they?

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science One Last Thing! Okay, so we know we will always need to know the encoding scheme to interpret scientific notation.Okay, so we know we will always need to know the encoding scheme to interpret scientific notation. But, once we know the encoding scheme for any given computer, we need to be able to encode in this scientific notation form …But, once we know the encoding scheme for any given computer, we need to be able to encode in this scientific notation form …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Fractional Value Numbers Consider the decimal (base 10) number: +5.75Consider the decimal (base 10) number: How can we encode this is switches?How can we encode this is switches? We already know how to do half of the encoding – the integer part (the numbers to the left of the decimal point).We already know how to do half of the encoding – the integer part (the numbers to the left of the decimal point). Let’s break the problem into two parts, the left hand side (of the decimal point) and the right hand side …Let’s break the problem into two parts, the left hand side (of the decimal point) and the right hand side …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Left Side of a Decimal Number Okay, our number is 5.75Okay, our number is 5.75 To convert the 5 10 to ? 2 :To convert the 5 10 to ? 2 : –Use successive division DivisionRemainder 5 / 2 = / 2 = / 2 = = 101 2

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Right Side of a Decimal Number On the left hand side, we divided successively by 2 to convertOn the left hand side, we divided successively by 2 to convert On the right hand side, we multiply successively by 2 to convertOn the right hand side, we multiply successively by 2 to convert –We are multiplying numbers by 2 to “promote” them to the left hand side of the decimal place. –Once promoted, we record them as a digit in our answer. This process is called extraction….This process is called extraction….

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Extraction STEP ONE: Draw a table with two columns. Label the columns for the expression and the extraction, respectively. ExpressionExtract.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Extraction STEP TWO: Write down your original number and multiply it by 2. Put the whole number part in the Extraction column. ExpressionExtract * 2 =

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Extraction STEP THREE: Bring down the fractional part (the number to the right of the decimal point) and multiply it by two. Extract the whole number, as before. Repeat until you extract 0. ExpressionExtract * 2 = * 2 = * 2 =

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Extraction STEP FOUR: Read the extraction column, from top to bottom. This number represents your binary equivalent. ExpressionExtract * 2 = * 2 = * 2 = = 110 2

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Both Sides Now = This isn’t in scientific notation yet, but at least we have figured out how to convert it to binary = This isn’t in scientific notation yet, but at least we have figured out how to convert it to binary Recall the steps so far:Recall the steps so far: –Do the problem in halves –For the left side of the decimal, use successive division by 2 and read the remainders from bottom to top –For the right hand side of the decimal, use successive multiplication by 2 and read the extractions from top to bottom

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Let’s Try One More … Let’s try another problem. This time, with a number that doesn’t convert to binary as easily …Let’s try another problem. This time, with a number that doesn’t convert to binary as easily … Let’s try this number:Let’s try this number: = ? 2

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Converting Remember our algorithm: left side by successive division, right side by successive multiplicationRemember our algorithm: left side by successive division, right side by successive multiplication

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Left Side of by successive division2 by successive divisionDivisionRemainder 2/2 = 1 0 1/0 = 0 1 Reading the remainders from bottom to top, 2 10 = 10 2

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Right Side of 2.54 Reading the extraction column, top to bottom: = What would have if we kept extracting, past.24 * 2?What would have if we kept extracting, past.24 * 2? Let’s convert our number back to Base-10 to see what happens …Let’s convert our number back to Base-10 to see what happens … DivisionExtraction.54 * 2 = * 2 = * 2 = * 2 = * 2 = * 2 = * 2 = * 2 = * 2 =

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Let’s Go Back the Other Way Putting back to base 10Putting back to base 10 Left hand side first, expanded notationLeft hand side first, expanded notation 10 2 = (0 * 2 0 ) + (1 * 2 1 ) = = = (0 * 2 0 ) + (1 * 2 1 ) = = 2 10 Now, to convert the right hand side…Now, to convert the right hand side…

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Right Side of a Decimal Number Remember, the left hand side represents powers of two … positive powers of twoRemember, the left hand side represents powers of two … positive powers of two Moving left from the decimal point, we saw the unit values were 2 0, 2 1, 2 2, 2 3, 2 4, etc.Moving left from the decimal point, we saw the unit values were 2 0, 2 1, 2 2, 2 3, 2 4, etc. Doesn’t it seem reasonable that the units to the right of the decimal represent negative powers of two?Doesn’t it seem reasonable that the units to the right of the decimal represent negative powers of two? Moving from the right of the decimal point, we will see unit values for 2 -1, 2 -2, 2 -3, 2 -4, 2 -5, etc.Moving from the right of the decimal point, we will see unit values for 2 -1, 2 -2, 2 -3, 2 -4, 2 -5, etc.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Okay, But What Does That Mean? Exactly what is a number to a negative power, such as 2 -1, 2 -2, 2 -3 ?Exactly what is a number to a negative power, such as 2 -1, 2 -2, 2 -3 ? These are numbers you already know we are just used to seeing them written in a different format:These are numbers you already know we are just used to seeing them written in a different format: 2 –1 1/2 1 ½.5 2 –2 1/2 2 ¼.25 2 –3 1/2 3 1/ /2 4 1/

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Back to Our Conversion … Remember, we are translating Remember, we are translating We finished the left hand side = 10 2 = 2 10We finished the left hand side = 10 2 = 2 10 Now for the right hand side:Now for the right hand side: = = –(1 * 2 -1 ) + (0* 2 -2 ) + (0* 2 -3 ) + (0* 2 -4 ) + (1* 2 -5 ) + (0* 2 -6 ) + (1* 2 -7 ) + (0* 2 -8 ) + (0* 2 -9 ) (1* 2 -7 ) + (0* 2 -8 ) + (0* 2 -9 ) –Which is equal to ½ + 1/32 + 1/128 (we can throw out the zero terms) –Which is equal to 69/128 =.539 Combining both sides, = Combining both sides, = But we started with 2.54! Why did we get the error?But we started with 2.54! Why did we get the error?

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science The Imprecision of Conversions We started with , took it to switch units in binary, and then back to decimalWe started with , took it to switch units in binary, and then back to decimal Our result was 2.539Our result was This is a precision error:This is a precision error: –2.539 / =.99, so our percentage error is 1%!!! As you might imagine, in large, multi-step calculations these errors can become significant enough for you to see if you are working in a package such as Excel….As you might imagine, in large, multi-step calculations these errors can become significant enough for you to see if you are working in a package such as Excel….

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Storing Binary in Scientific Notation Remember, we said if we could encode a decimal number in switch math, we were good to go.Remember, we said if we could encode a decimal number in switch math, we were good to go. Decimal numbers are usually stored in a binary version of scientific notation.Decimal numbers are usually stored in a binary version of scientific notation. If we can take our translation of 2.54, and store it in a binary version of scientific notation, we can quit!If we can take our translation of 2.54, and store it in a binary version of scientific notation, we can quit!

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Last Step There are several switch encoding schemes for scientific notation.There are several switch encoding schemes for scientific notation. The good news, remember, is that you (and the computer!) will always have to be told which encoding scheme to use.The good news, remember, is that you (and the computer!) will always have to be told which encoding scheme to use. One common encoding scheme is 16-bit encoding …One common encoding scheme is 16-bit encoding …

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science 16 Bit Scientific Notation Encoding In 16 bit encoding, 16 bits (or switches) are allocated to the numeric part of a number expressed in scientific notation.In 16 bit encoding, 16 bits (or switches) are allocated to the numeric part of a number expressed in scientific notation. There are a few different flavors of 16 bit encoding, with a different allocation of switches between the mantissa and the exponent.There are a few different flavors of 16 bit encoding, with a different allocation of switches between the mantissa and the exponent.

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science One 16 Bit Encoding in Detail Remember the parts of a number in scientific notation? – the mantissa, base and exponent?Remember the parts of a number in scientific notation? – the mantissa, base and exponent? Each is assigned to specific locations in the 16 bit switch pattern. In the variation we are looking at first:Each is assigned to specific locations in the 16 bit switch pattern. In the variation we are looking at first: –Switch 1 = Sign of the mantissa –(Decimal point assumed to go next, but isn’t stored) –Switches 2-10 – next 9 switches are for the mantissa –Switch 11 – Sign of the exponent –Switches – next 5 switches are for the exponent

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science 16 Bit: More What happened to the base? We don’t have to store that, because it will always be base two, the binary base from the world of switchesWhat happened to the base? We don’t have to store that, because it will always be base two, the binary base from the world of switches Don’t need to store the decimal point, because the encoding scheme will guarantee it is placed correctly when decodedDon’t need to store the decimal point, because the encoding scheme will guarantee it is placed correctly when decoded There’s only one problem: our number must be “normalized” before encodingThere’s only one problem: our number must be “normalized” before encoding –This means that we need to adjust the exponent as required to insure that the first significant digit is the first digit to the right of the decimal point

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Normalizing Take the number , which is really * 2 0Take the number , which is really * 2 0 Before we can store this number in scientific notation, we must normalize it.Before we can store this number in scientific notation, we must normalize it. We have to adjust the exponent until the first significant digit, which is the leftmost 1, is the first digit to the right of the decimal point.We have to adjust the exponent until the first significant digit, which is the leftmost 1, is the first digit to the right of the decimal point. In other words, we have to move the decimal place in our example 3 places to the left, so that the number become In other words, we have to move the decimal place in our example 3 places to the left, so that the number become

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Normalizing How can we legally do this, without changing the value of the number?How can we legally do this, without changing the value of the number? Every time you move the decimal place to the left, you must adjust the exponent by a positive increment.Every time you move the decimal place to the left, you must adjust the exponent by a positive increment. In our case, we moved 3 decimal points to the left, so our new exponent is 2 3In our case, we moved 3 decimal points to the left, so our new exponent is 2 3 In other words, * 2 0 = * 2 3In other words, * 2 0 = * 2 3

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Normalizing Examples A couple more, to make sure we have it:A couple more, to make sure we have it: * 2 0 = * * 2 0 = * * 2 0 =.1011 * * 2 0 =.1011 * * 2 0 =.1 * * 2 0 =.1 * * 2 0 =.1 * * 2 0 =.1 * 2 -2

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Algorithm 1. Convert the base ten number to base two, one side of the decimal place at a time1. Convert the base ten number to base two, one side of the decimal place at a time –Left hand side, successive division –Right hand side, successive multiplication In our case, = In our case, =

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Algorithm (con’t) Put number in normalized form * 2 0 = * 2 2Put number in normalized form * 2 0 = * 2 2 Determine what the encoding scheme isDetermine what the encoding scheme is For the sake of our problem, assume the following 16 bit encoding:For the sake of our problem, assume the following 16 bit encoding: –1 = Sign of mantissa –2-12 = Mantissa –13 = Sign of exponent –14-16 = Exponent

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Algorithm (con’t) Using the described notation system, the decimal would be stored in switch binary math as the following pattern of zeros and ones:

N301: Fundamental Computer Science Concepts Copyright ©2004  Department of Computer & Information Science Questions?