Introduction to Computers and Programming. Numeric Values

Similar documents
Divide: Paper & Pencil

Chapter 3: Arithmetic for Computers

COMP2611: Computer Organization. Data Representation

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CHW 261: Logic Design

COMP Overview of Tutorial #2

Module 2: Computer Arithmetic

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Number Systems. Both numbers are positive

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers


Inf2C - Computer Systems Lecture 2 Data Representation

Chapter Three. Arithmetic

Computer Organisation CS303

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Numeric Encodings Prof. James L. Frankel Harvard University

MACHINE LEVEL REPRESENTATION OF DATA

Introduction to Computer Science-103. Midterm

CS101 Lecture 04: Binary Arithmetic

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Organisasi Sistem Komputer

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Digital Fundamentals

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

Chapter 4. Operations on Data

FLOATING POINT NUMBERS

Number Systems and Computer Arithmetic

Exponential Numbers ID1050 Quantitative & Qualitative Reasoning

CS & IT Conversions. Magnitude 10,000 1,

ECE232: Hardware Organization and Design

Number Systems CHAPTER Positional Number Systems

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

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

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

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

Floating Point Arithmetic

Signed Binary Numbers

Number Systems (2.1.1)

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

M1 Computers and Data

Objectives. Connecting with Computer Science 2

Chapter 2 Data Representations

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

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

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Data Representations & Arithmetic Operations

unused unused unused unused unused unused

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

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

FLOATING POINT NUMBERS

Number System. Introduction. Decimal Numbers

3.5 Floating Point: Overview

Chapter 5 : Computer Arithmetic

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Chapter 1 Review of Number Systems

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

3.1 DATA REPRESENTATION (PART C)

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Numerical Representations On The Computer: Negative And Rational Numbers

CS 101: Computer Programming and Utilization

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

CO212 Lecture 10: Arithmetic & Logical Unit

Numerical Representations On The Computer: Negative And Rational Numbers

ECE 30 Introduction to Computer Engineering

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Computer Arithmetic Floating Point

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Data Representation in Computer Memory

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CHAPTER 5: Representing Numerical Data

The. Binary. Number System

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

Number representations

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

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

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

Introduction to Scientific Computing Lecture 1

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

A Level Computing. Contents. For the Exam:

Floating Point Numbers. Lecture 9 CAP

Chapter 10 - Computer Arithmetic

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Data Representation 1

Chapter 4 Section 2 Operations on Decimals

Scientific Computing. Error Analysis

Transcription:

Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 5 Reading: B pp. 47-71 Sept 1 003 Numeric Values Storing the value of 5 10 using ASCII: 00110010 00110101 Binary notation: 00000000 000011001 Base ten system Representation 3 7 5 Position's quantity Hundred Ten One 1. Binary place 5 4 3 1 0. Position's quantity 3 16 8 4 1 Representation Base two system 1 0 1 1 3. Example binary pattern 4. Total (. x 3.) 1 0 1 1 0 1 3 + 0 + 8 + 4 + 0 + 1 = 45 Position's quantity Eight Four Two One

Finding Binary Representation of Large Values 1. Divide the value by and record the remainder. As long as the quotient obtained is not 0, continue to divide the newest quotient by and record the remainder 3. Now that a quotient of 0 has been obtained, the binary representation of the original value consists of the remainders listed from right to left in the order they were recorded 0 R1 1 1 R1 3 0 R0 6 6 R1 13 1 1 0 1 The Binary System Decimal: Position represents a power of 10 53810 = 5x103 + 3x10 +8x10 1 +x10 0 Binary: Position represents a power of 1011 = 1x 3 + 0x + 1x 1 + 1x 0 = 8 + 0 + + 1 = 11 10 Binary addition bit number 7 6 5 4 3 1 0 A byte 0 1 0 1 0 0 1 1 bit value 18 64 3 16 8 4 1

Representing Negative Numbers Using one byte, any suggestions for representing negative numbers? E.g., 00010011 = 19 10. How to represent 19 10 in binary? Reserve 1 bit (#7) for sign, 7 bits for number (sign magnitude) 00000001 = 1 10 10000001 = -1 10 00010011 = 19 10 10010011 = -19 10 Representing Negative Numbers One s complement invert each bit 00010011 = 19 10 11101100 = -19 10 0 10 : 00000000 and 11111111 Two s complement invert each bit and add 1 00010011 = 19 10 11101101 = -19 10 Try to negate 0: 0 10 = 00000000 invert: 00000000 Æ 11111111 add 1: 11111111 + 00000001 = 00000000

Two s Complement Notation Systems Bit Pattern Value Represented Bit Pattern Value Represented 011 010 001 000 111 110 101 100 3 1 0-1 - -3-4 0111 7 0110 6 0101 5 0100 4 0011 3 0010 0001 1 0000 0 1111-1 1110-1101 -3 1100-4 1011-5 1010-6 1001-7 1000-8 Addition Problem in base ten 3 + -3 +- 7 +-5 Problem in two's complement 0011 + 0010 0101 1101 + 1110 1011 0111 + 1011 0010 Answer in base ten 5-5

Example: we are using 8 bit two's complement and have the problem 97-81. 97 0 1 1 0 0 0 0 1-81 +1 0 1 0 1 1 1 1 16 0 0 0 1 0 0 0 0 Summary: One s/two s Complement Note that in sign magnitude and in one's complement there are two possible representations of 0, and we can represent every integer n with -( k -1) d n d k -1 with a k-bit field. With two's complement there is only one representation of 0, and we can represent the integers n with - k d n d k -1. The most significant advantage of two's complement is the fact that subtraction can be performed with addition circuitry.

The Problem of Overflow Overflow: when a value to be represented falls outside the range of values that can be represented. An overflow is indicated if the addition of two positive values results in the pattern for a negative value or vice versa. Remember: small values can accumulate to produce large numbers. Fractions in Binary Each position is assigned a quantity of twice the size of the one to its right. 101.101 =? 1. Binary place 1 0-1 - -3. Position's quantity 3. Example binary pattern 4. Total ( x 3) 4 1 1/ 1/4 1/8 1 0 1. 1 0 1 4 + 0 + 1 + 1/+ 0 +1/8 = 5 5/8 10.001 + 100.000 111.001

Floating Point representation To represent a floating point number the number is divided into two parts: the integer and the fraction 3.1415 has integer 3 and fraction 0.1415 Converting FP to binary: Convert integer part to binary Convert fraction part to binary Put a decimal point between the two numbers Floating Point representation Assume 1 bits to represent the integer part and 4 bits to represent the fraction: 71.345 = +1000111.0101

point Instead we use Normalization Normalization To represent +1000111.0101 Store sign, all bits, and the position of decimal Move the decimal point so that there is only one 1 to the left of the decimal point. To indicate the original value of the number, multiply by where e is the number of bits that the decimal point moved, positive for left movement, negative for right movement Store: The sign The exponent The mantissa Sign bit Bit positions Exponent e Mantissa Excess (or bias) Notation Alternative to two s complement used to store the exponent for floating point numbers. Bit Pattern 111 110 101 100 011 010 001 000 Value Represented 3 1 0-1 - -3-4 With 3 bits we have excess 4 (= 3-1 )

Excess (or bias) Notation Bit Pattern Value Represented With 4 bits we have excess 8 (= 4-1 ) 1111 1110 1101 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001 7 6 5 4 3 1 0-1 - -3-4 -5-6 -7 0000-8 With N bits we have excess N-1 We add the magic number, N-1, to the integer, change the result to binary, and add 0 s (on the left) to make up N bits. FP Representation The standard IEEE representation for FP uses 3 bits for single-precision format: 1 bit sign 8 bits exponent (excess 17 = 8-1 -1) 3 bits mantissa Representation. Store the: Sign as 0 (positive), 1 (negative) Exponent (power of ) as excess17 Mantissa as an unsigned integer

Example: FP Representation Consider a 16-bit representation with 1 bit sign 5 bits exponent (excess 16 = 5-1 ) 10 bits mantissa 0 10011 1101100000 The sign 0 represents positive The exponent 10011 = 1910 represents 3 The mantissa is.1101100000 (1 to left of. is not stored, it is understood) Coding the value 5/8 Original representation 5 / 8 Base representation 1 0. 1 0 1 Raw bit pattern 1 0 1 0 1 Lost bit Sign bit Exponent Mantissa Truncation Errors