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

Similar documents
Floating Point Arithmetic

IEEE-754 floating-point

Numeric Encodings Prof. James L. Frankel Harvard University

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

COMP2611: Computer Organization. Data Representation

MACHINE LEVEL REPRESENTATION OF DATA

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

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

IEEE Standard for Floating-Point Arithmetic: 754

COMP2121: Microprocessors and Interfacing. Number Systems

Number Representations

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

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

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

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Module 2: Computer Arithmetic

CHW 261: Logic Design

Inf2C - Computer Systems Lecture 2 Data Representation

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

M1 Computers and Data

Introduction to Computers and Programming. Numeric Values

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

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

Number Systems. Both numbers are positive

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

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

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

Chapter 2. Data Representation in Computer Systems

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

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

COMP Overview of Tutorial #2

Chapter Three. Arithmetic

Number System. Introduction. Decimal Numbers

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

Chapter 3: Arithmetic for Computers

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

Organisasi Sistem Komputer

ECE331: Hardware Organization and Design

ECE232: Hardware Organization and Design

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

ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Introduction to Scientific Computing Lecture 1

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Number Systems CHAPTER Positional Number Systems

Final Labs and Tutors

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

15213 Recitation 2: Floating Point

Basic data types. Building blocks of computation

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

3.5 Floating Point: Overview

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

CS 101: Computer Programming and Utilization

Digital Fundamentals

Floating-Point Arithmetic

±M R ±E, S M CHARACTERISTIC MANTISSA 1 k j

Numerical computing. How computers store real numbers and the problems that result

Floating-Point Arithmetic

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

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

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

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

Divide: Paper & Pencil


Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

Representing and Manipulating Floating Points. Jo, Heeseung

INTEGER REPRESENTATIONS

Floating-Point Arithmetic

COPYRIGHTED MATERIAL. Number Systems. 1.1 Analogue Versus Digital

Objectives. Connecting with Computer Science 2

Chapter 4: Data Representations

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

CHAPTER 2 Data Representation in Computer Systems

unused unused unused unused unused unused

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Computer Systems Programming. Practice Midterm. Name:

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

Computer Organisation CS303

Signed umbers. Sign/Magnitude otation

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Floating Point Numbers. Lecture 9 CAP

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

CHAPTER 1 Numerical Representation

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

Integers and Floating Point

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

EE292: Fundamentals of ECE

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

Representing and Manipulating Floating Points

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

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.

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Transcription:

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

Part 1: Data Representation Our goal: revisit and re-establish fundamental of mathematics for the computer architecture course Overview: what are bits & bytes? bit and arithmetic value? bit and hexadecimal? character set in PCs? how to do binary arithmetic operation (+,-,*,/)? integer representation in PCs: signed and unsigned binary and floating point floating point representation? order of byte in computers big endian vs. little endian 2

Conversion in Between Float and Binary 3

Floating point means a number with an integral part and a fractional part Converting floating point in between decimal and binary Place values: Floating point 2 5 2 4 2 3 2 2 2 1 2 0 2-1 2-2 2-3 2-4 2-5 32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125 Integral part Fractional part Example: 4.5 (decimal) = 100.1 (binary) 4

Converting floating point Example: 6.25 = 110.01 Method: 6 = 110.25 x 2 = 0.5.5 x 2 = 1.0 (Stop when fractional part is 0) 110.01 Example: 6.2 110.001100110011 110 (Integral part: convert in the usual way).5 (Fractional part: successive multiplication by 2) 6 = 110.2 x 2 = 0.4.4 x 2 = 0.8.8 x 2 = 1.6.6 x 2 = 1.2.2 x 2 = 0.4 (repeats) 110.0011 0011 0011 5

One more example to convert floating point Example: 6.4? 110.0110 0110 0110 How the floating binary number stored in computer? 6

How Float Represented in Computer 7

Floating point representation in computer Computers use a form of scientific notation for floatingpoint representation Numbers written in scientific notation have three basic components: Example: 1.101 x 2 010 use base 2 instead of base 10 Sign Mantissa Exponent Exponent specifies the order of magnitude in a base Mantissa specifies most significant part of value Sign specifies negative or positive 8

Floating point representation in computer Computer representation of a floating-point number consists of three fixed-size fields: This is the standard arrangement of these fields. 9

Floating point representation in computer (1) The one-bit sign field is the sign of the stored value. (2) The size of the exponent field, determines the range of values that can be represented. (3) The size of the significand determines the precision of the representation. 10

Floating point representation in computer single-precision (32 bits) floating point representation defined by IEEE standard 754 1 sign bit "biased" exponent (8 bits) "normalized" mantissa (23 bits) Floating point = (-1) s x (1.m) x 2 (e-bias) Notice that the 1 in 1.m is always assumed. where, bias = 127 11

Floating point representation in computer double-precision (64 bits) floating point representation defined by IEEE standard 754 1 sign bit "biased" exponent (11 bits) "normalized" mantissa (52 bits) Floating point = (-1) s x (1.m) x 2 (e-bias) where, bias = 1023 12

Floating point representation: example 1 Given decimal real number 6.25, what is its single precision floating number stored in PC? Step 1. 6.25 (decimal) = 110.01 (binary) Step 2. Move the radix point until a single 1 appears on the left, and multiply by the corresponding power of 2 1.1001x2 2 so the sign bit is 0 (positive) the biased exponent is 2 + 127 = 129 = 10000001 = e and the normalized mantissa is 1001 (drop the 1, rest zero-fill). 0 10000001 10010000000000000000000 0100 0000 1100 1000 0000 0000 0000 0000 40C80000 hexadecimal 13

Floating point representation: example 2 Given decimal real number 6.2, what is its single precision floating number stored in PC? Step 1. 6.2 (decimal) = 110.001100110011 (binary) Step 2. Move the radix point until a single 1 appears on the left, and multiply by the corresponding power of 2 = 1.10001100110011 x2 2 so the sign bit is 0 (positive) the biased exponent is 2 + 127 = 129= 10000001 and the normalized mantissa is 10001100110011 0 10000001 10001100110011001100110 0100 0000 1100 0110 0110 0110 0110 0110 40C66666 hexadecimal 14

Floating point representation: example 3 Double value in memory (in hex): 4024 0000 0000 0000 what s its binary: 0100 0000 0010 0100 0000 0000 0000 0000 what s its decimal? s (bit 64) = 0 = positive number e (bits 52 to 62) = 100 0000 0010 = 1024 + 2 = 1026 m (bits 0 to 51) =.0100 0000 0000 0000 0000 Value = (-1) 0 x (1.01) b x 2 (1026-1023) = 1x (2 0 +2-2 )x2 3 =(1+1/4)x8=8+2=10 15

Floating point representation: example 4 What decimal floating-point number is represented by 0xC1870000? 1100 0001 1000 0111 0000 0000 0000 0000 1 10000011 00001110000000000000000 Sign Biased exponent Normalized mantissa so the sign is negative the unbiased exponent is 131-127 = 4 and the unnormalized mantissa is 1.00001110000000000000000 (add the 1 left of the radix point). Move the radix point 4 places to the right: 10000.111-10000.111 = -16.875 16

Byte Order: Big Endian vs. Little Endian 17

Byte order Byte ordering, or endianness, is a major computer architectural consideration Byte ordering describes how data stored in memory, which is visible and important to programmer More details later in the course, here we introduce basic concept 18

Byte order If we have a two-byte integer, the integer may be stored so that the least significant byte is followed by the most significant byte or vice versa. In little endian machines, the least significant byte is stored in lowest memory location. (DEC, IBM (Intel Pentium)) Big endian machines store the most significant byte in lowest memory. (Motorola, Sun SPARC) 19

Big and little endian: an example Given 32 bits (4 bytes) integer (or single-precision floating point numbers) 0x 90AB12CD, the 4 bytes are: 90, AB, 12, CD, How can we store these values into memory? Big Endian In big endian, we store the most significant byte in the smallest address. Here's how it would look: Little Endian In little endian, we store the least significant byte in the smallest address. Here's how it would look: Address Value 1000 90 1001 AB 1002 12 1003 CD Address Value 1000 CD 1001 12 1002 AB 1003 90 20

Endianness: consequence for programmer For JAVA programmer, we have to know: - Everything in Java binary format files is stored big-endian, i.e. MSB (Most Significant Byte) first. - JAVA is platform independent because and Java hides internal endianness from us no matter what internal byte order used (i.e. Mac is big-endian order and intel PC is little-endian) For C programmer, we have to know: - Most files compiled by C use little-endian in windows PC For both C and JAVA programmer, we have to fix the byte order problem when transferring data files between computers for which the byte ordering differs 21

Summary: conceptual issues Bits grouped into sets to represent Integers Characters Floating point values Signed integers can be represented as Sign magnitude One's complement Two's complement Bytes of integer can be numbered in Big-endian order and Little-endian order 22

Summary: technical issues Conversion in between Binary, Hexadecimal, Decimal, Single Float and Double Signed Integer represented by Sign magnitude One's complement Two's complement The consequence of byte order to our programmers 23

Thank you for your attendance Any questions? 24