Department of Computer Science Georgia State University

Slides:



Advertisements
Similar presentations
Chapter 2: Data Representation
Advertisements

Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
Chapter 1.7 Storing Fractions. Excess Notation, continued… In this notation, "m" indicates the total number of bits. For us (working with 8 bits), it.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
Lecture 8 Floating point format
Binary Number Systems.
Binary Representation and Computer Arithmetic
The Binary Number System
Simple Data Type Representation and conversion of numbers
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Arithmetic Nizamettin AYDIN
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
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.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
9.4 FLOATING-POINT REPRESENTATION
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
The Teacher CP4 Binary and all that… CP4 Revision.
Negative Numbers An alternative way to find the 2's complement Starting at the right 1. Copy bits until you reach the first Flip all the remaining.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013.
IT1004: Data Representation and Organization Negative number representation.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.7 Instructor: Lin Chen Sept 2013.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Representing Positive and Negative Numbers
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Arithmetic – Part I
Chapter 9 Computer Arithmetic
Computer Representation of Information
William Stallings Computer Organization and Architecture 8th Edition
CHAPTER 5: Representing Numerical Data
Floating Point Numbers
Nat 4/5 Computing Science Lesson 1: Binary
Floating Point Representations
Fundamentals of Computer Science
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. Clincy Professor of CS
Introduction To Computer Science
Dr. Clincy Professor of CS
William Stallings Computer Organization and Architecture 7th Edition
ECE 2110: Introduction to Digital Systems
Data Structures Mohammed Thajeel To the second year students
Data Representation Data Types Complements Fixed Point Representation
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
ECEG-3202 Computer Architecture and Organization
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
Number Representation
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Chapter 8 Computer Arithmetic
Storing Integers and Fractions
COMS 161 Introduction to Computing
Chapter3 Fixed Point Representation
OBJECTIVES After reading this chapter, the reader should be able to :
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

Department of Computer Science Georgia State University Data Manipulation Department of Computer Science Georgia State University

What will be covered? A review on binary notation Fractions in binary Binary addition Storing integers Storing fractions

A review on binary notation How to convert a binary into a decimal (base 10)? ( 1 0 1 1 1 )2= ( ? )10

( 1 0 1 1 1 )2= ( ? )10 23 1 Position 4 3 2 1 Position’s quantity 24 23 22 21 20 16 8 4 2 1 1 0 1 1 1 ⨯16 ⨯ 8 ⨯ 4 ⨯ 2 ⨯ 1 + + + + = 16 + 0 + 4 + 2 + 1 = 23

Fractions in Binary 1 0 1 . 0 1 1

Fractions in Binary Decimal Point 1 0 1 . 0 1 1

1 0 1 . 0 1 1 Fractions in Binary Radix Point Integer Part 1 0 1 . 0 1 1 Integer Part Fractional Part

( 1 0 1 .0 1 1 )2= ( ? )10 1 . Position 2 1 -1 -2 -3 Position’s quantity 22 21 20 2-1 2-2 2-3 4 2 1 ½ ¼ ⅛ 1 0 1 0 1 1 ⨯4 ⨯ 2 ⨯ 1 ⨯ ½ ⨯ ¼ ⨯ ⅛ + + + + + = 4 + 0 + 1 + 0 + ¼ + ⅛ = 5 ⅜

Practice 1 ( 1 0 . 0 1 1 )2= ( ? )10 ½ ¼ ⅛ Position 7 6 5 4 3 2 1 . -1 ( 1 0 . 0 1 1 )2= ( ? )10 Position 7 6 5 4 3 2 1 . -1 -2 -3 Position's quantity 27 26 25 24 23 22 21 20 2-1 2-2 2-3 128 64 32 16 8 ½ ¼ ⅛

Practice 1 ( 1 0 . 1 0 1 )2= ( ? )10 1 0 . 1 0 1 Position's quantity 128 64 32 16 8 4 2 1 . ½ ¼ ⅛ + ½ + ⅛ 2 = 2⅝ ( 1 0 . 0 1 1 )2= ( 2 + ½ + ⅛ )10=( 2⅝ ) 10

Binary Addition Base 2 Base 10 1 1 1 0 1 0 + 1 1 0 1 1 ? 5 8 + 2 7 ?

Binary Addition Base 10 1 5 8 + 2 7 5 8 2 7 8 5

Binary Addition Base 2 1 1 1 0 1 0 + 1 1 0 1 1

Binary Addition + 0 + 1 1 + 0 1 + 1 ⨯ 1 1 1 2

1 1 1 0 1 0 + 1 1 0 1 1 1 1 1 1 Binary Addition Integers Base 2 1 1 1 + 1 1 0 1 1 Integers 1 1 1 1

Binary Addition Base 2 1 0 . 0 1 1 + 1 0 0 . 1 1 0 Fractions 1 1 1 . 1

Storing Integers In the “real world” of mathematics, computers must represent both positive and negative binary numbers for positive and negative integers. For example, even when dealing with positive arguments, mathematical operations may produce a negative result. Example : 125 - 130 = -5 Thus needs to be a consistent method of representing negative numbers in computers.

Storing Integers Sign-Magnitude The simplest conceptual format Two’s complement The most popular system for representing integers within today’s computers. Excess notation Representing a fixed length binary number in computer circuits.

Sign-Magnitude Sign bit : leftmost bit 0 represents positive, 1 represents negative Magnitude : the remaining bits The same as binary notation of absolute value E.g. 4-bit sign-magnitude format But….... Sign Magnitude 0000 1000 +0 -0 E.g. Using 4-bit sign-magnitude format Calculate 110+(-1)10 +1 is stored as 0001 -1 is stored as 1001 0011 represents 3 1011 represents -3 0001 + 1001 1010 = -210

Two’s complement notation Definition: “The two’s complement of a binary integer is the 1’s complement of the number plus 1.” For each bit, change 0 to 1, and 1 to 0

Two’s complement notation How to encode an integer in two’s complement notation? For positive integers, keep the binary representation For negative integers, Start with N-bit representation of their absolute values (positive integer) Complement each bit (change 0 to 1, and 1 to 0) Add one (Binary addition algorithm) “Complement and Add One”

Two’s complement notation How to encode an integer in two’s complement notation? For positive integers, keep the binary representation. For negative integers, Start with N-bit representation of their absolute values (positive integer) Complement each bit (change 0 to 1, and 1 to 0) Add one (Binary addition algorithm) E.g. Represent -610 in Two’s complement The positive integer: 0 1 1 0 610 Complement each bit: 1 0 0 1 Add one: + 0 0 0 1 1 0 1 0 -610

Two’s complement notation Another simple way to get the two’s complement notation for a negative integer “Copy until one and Complement” 0 1 1 0 6 Copy the bits from right to left until a 1 has been copied Complement the remaining bits 0  1 1  0 1 0 1 0 - 6

Two’s complement notation Another simple way to get the two’s complement notation for a negative integer “Copy until one and Complement” The positive integer: 0 1 1 0 Copy until 1 1 0 Complement remaining: 1 0 1 0 -610 610 610 -610 The positive integer: 0 1 1 0 Complement each bit: 1 0 0 1 Add one: + 0 0 0 1 1 0 1 0 “Complement and Add one”

Two’s complement notation E.g. Represent -410 in Two’s complement using 4-bit pattern The positive integer: 0 1 0 0 410 Copy until 1: 1 0 0 Complement remaining: 1 1 0 0 -410 E.g. Represent -810 in Two’s complement using 4-bit pattern The positive integer: 1 0 0 0 810 Copy until 1: 1 0 0 0 Complement remaining: 1 0 0 0 -810

Figure 1.19 Two’s complement notation systems -4 ~ +3 -8 ~ +7

Two’s complement notation Range of integers with Two’s complement 3-bit : -4 ~ +3 4-bit : -8 ~ +7 5-bit : -16 ~ +15 8-bit : -128 ~ +127 N-bit : -23-1 ~ +23-1-1 -24-1 ~ +24-1-1 -25-1 ~ +25-1-1 -28-1 ~ +28-1-1 -2N-1 ~ +2N-1-1 So In order to store value 8 in two’ complement notation, how many bits should be used at least?

Two’s complement notation How to decode a Two’s complement notation? Check “Sign bit” Sign bit = 0 ( positive number) Convert the binary number to a decimal directly Sign bit = 1 ( negative number) Do the “ Copy until 1 and Complement ” process Convert binary into decimal E.g. Decode Two’s complement notation 1010 Two’s complement: 1 0 1 0 Negative Copy until one: 1 0 Complement remaining: 0 1 1 0 The positive integer: 0 1 1 0 610 Result: -610

Practice 2 Decode the following two’s complement (8-bit) 1 1 1 0 1 1 1 0

Practice 2 Decode the following two’s complement (8-bit) 1 1 1 0 1 1 1 0 Complement Copy 0 0 0 1 0 0 1 0 = 1 *16 + 1*2 = 18 Final answer: - 18

Addition in Two’s Complement

Overflow problem 9 is not in range -8 ~ 7, thus error happened. Problem in base ten Problem in 4-bit Two’s complement 5 0 1 0 1 + 4 + 0 1 0 0 1 0 0 1 Answer in base ten 9 -7 9 is not in range -8 ~ 7, thus error happened. We call this phenomenon as overflow.

Excess Notation Excess four conversion table 7 7 6 5 4 3 2 1

Storing Fractions Besides storing the binary representation, we need to store the position of radix. Radix Point 1 0 1 . 0 1 1 One popular way to store fractions in computer is called floating-point notation.

Floating-point Notation Scientific notation ±M x BE (M < 1) M is the mantissa, B is the exponent base (usually 2), and E is the exponent Normalized form E.g. - 0.25 * 102 , 0.11 * 22 , - 0.1* 2-3 8 bits Sign bit Exponent ( 3 bits) Mantissa ( 4 bits)

Error can be reduced by using a longer mantissa field Truncation errors Encoding the value 2 ⅝ 2½ 0 1 1 0 Error can be reduced by using a longer mantissa field

What you have learned ? Binary System Binary notation Fractions in binary Binary addition How to store integers and fractions in computer? Two’s complement notation Overflow problem Floating point notation (scientific notation) Truncation error

Thank you !

Floating-point Notation Decode a floating-point notation 1 8 bits Sign bit Exponent Mantissa Scientific notation : ± . M x B E - 4 + . 1011 x 2 110- 4 + . 1011 x 2 6- 4 + . 1011 x 2 2 2¾ 10.11

Practice 3 ( 5⅝)10= ( ? )2 0 1 0 1 . 1 0 1 ½ ¼ ⅛ 5 = 4+1 ⅝ = ½ + ⅛ ( 5⅝)10= ( ? )2 0 1 0 1 . 1 0 1 Position's quantity 128 64 32 16 8 4 2 1 . ½ ¼ ⅛ 5 = 4+1 ⅝ = ½ + ⅛

Two’s complement notation How to encode an integer in two’s complement notation? For positive integers, keep the binary representation. For negative integers, Start with N-bit representation of absolute value (positive integer) Complement each bit (change 0 to 1, and 1 to 0) Add one (Binary addition algorithm) E.g. Represent -410 in Two’s complement The positive integer: 0 1 0 0 410 Complement each bit: 1 0 1 1 Add one: + 0 0 0 1 1 1 0 0 -410

Answer ( 1 1 . 0 1 )2= ( 1*2 + 1*1 + 0*0.5+1*0.25 )10 ( 0 . 1 0 1 )2= ( 0*1 + 1*0.5 + 0*0.25 + 1*0.125 )10 ( 4.5 )10= ( 1 0 0 . 1 )2 ( 5.625)10= ( 1 0 1 . 1 0 1 )2 Position 7 6 5 4 3 2 1 . -1 -2 -3 Position's quantity 27 26 25 24 23 22 21 20 2-1 2-2 2-3 128 64 32 16 8 1/2 1/4 1/8

Patterns that Add Up to Zero How to represent -1 ? Find a particular bit pattern results that represents zero when added to one. 0001 + 1111 0000 1 -1 1 How to represent -3 ? Find a particular bit pattern results that represents zero when added to three. 0011 + 1101 0000 3 -3 1

Floating-point Notation Decode a floating-point notation 1 8 bits Sign bit Exponent Mantissa Scientific notation : ± 0 . M x B E - 4 . 0 1 0 1 0 1 1 0 . 1 0 1 1 1 . 0 1 0 1 1 0.101011 * 2-1 0.101011 * 21 0.101011 * 22 + 0 . 1011 x 2 110- 4 + 0 . 1011 x 2 6- 4 + 0 . 1011 x 2 2 10.11 2¾

Exercises 1 ( 5⅝)10= ( ? )2 5 = 4 +1 ⅝ = ½ + ⅛ 1 0 1 . 1 0 1 Position ( 5⅝)10= ( ? )2 5 = 4 +1 ⅝ = ½ + ⅛ 1 0 1 . 1 0 1 Position 7 6 5 4 3 2 1 . -1 -2 -3 Position's quantity 27 26 25 24 23 22 21 20 2-1 2-2 2-3 128 64 32 16 8 1/2 1/4 1/8

( 1 0 1 1 1 )2= ( ? )10 23 1 16 8 4 2 1 16 + + + 4 2 1 = 23