Chapter 2 Representing and Manipulating Information Prof. Qi Tian CS 3843 Fall 2013 1.

Slides:



Advertisements
Similar presentations
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Advertisements

2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 2 Number Systems.
Data Representation Computer Organization &
Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.

Data Representation ICS 233
Floating Point Numbers
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 2 Bits, Data Types & Operations Integer Representation Floating-point Representation.
Chapter 5 Data representation.
Simple Data Type Representation and conversion of numbers
Data Representation – Binary Numbers
Computers Organization & Assembly Language
CS 3843 Final Exam Review Fall 2013 December 5, 2013.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
Computer Architecture
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Data Representation and Computer Arithmetic
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Number Systems Spring Semester 2013Programming and Data Structure1.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
Floating Point Numbers Topics –IEEE Floating Point Standard –Rounding –Floating Point Operations –Mathematical properties.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Ahmad Almulhem, KFUPM 2009 COE 202: Digital Logic Design Number Systems Part 4 Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
1 Information Representation in Computer Lecture Nine.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
CS 3843 Computer Organization Prof. Qi Tian Fall 2013
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
11001 / 101, / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the result.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)
Data Representation COE 308 Computer Architecture
Programming and Data Structure
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Lecture No. 4 Number Systems
Number Representation
2.4. Floating Point Numbers
Data Representation Binary Numbers Binary Addition
Recitation 4&5 and review 1 & 2 & 3
Standard Data Encoding
Topics IEEE Floating Point Standard Rounding Floating Point Operations
11001 / 101 , / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the.
What to bring: iCard, pens/pencils (They provide the scratch paper)
Data Representation COE 301 Computer Organization
Chapter 2 Bits, Data Types & Operations Integer Representation
Data Representation Data Types Complements Fixed Point Representation
CS201 - Lecture 5 Floating Point
Digital Logic & Design Lecture 03.
COMS 161 Introduction to Computing
Data Representation ICS 233
Data Representation COE 308 Computer Architecture
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Chapter 2 Representing and Manipulating Information Prof. Qi Tian CS 3843 Fall

Summary of Lectures (Monday) – Section Rounding Example – In-class Quiz 2 – Reminder: Midterm 1 on Monday Oct. 7, 2013 – Practice Problems for Midterm One 2

Summary of Lectures (Friday) – IEEE Rounding Methods – Practice Problem – Quiz 2 next Monday – Midterm 1 on Monday Oct. 7, (Wednesday) – Examples for IEEE Floating Point Representation (Monday) – Section 2.4 IEEE Floating Point Representation (cont.) 3

Summary of Lectures (Friday) – Section 2.4 IEEE Floating Point Representation (cont.) (Wednesday) – Section 2.4 IEEE Floating Point Representation (Monday) – Section Unsigned Addition and Unsigned Subtraction – Section Two’s Complement Addition – Quiz 1 4

Summary of Lectures (Friday) – Questions on P.9 of Assignment 1 – Section Unsigned Addition – Quiz (Wednesday) – Section Shift Operations Practice Problem 4 – Questions on Assignment (Monday) – Practice Problems 1-3 5

Summary of Lectures (Friday) – Section Representing Negative Numbers Sign & Magnitude System Two’s Complement System One’s Complement System (Wednesday) – Section Word size/data size/addressing and byte ordering Boolean Algebra and Logical Operations in C 6

Summary of Lectures (Friday) – Conversion between decimal and base R number Integer Fractional number (Wednesday) – Syllabus – Information Storage – Conversion between Binary and Hexadecimal Number 7

Practice Problem 1 - Bit-level Operations in C C expressionBinary RepresentationBinary ResultHexadecimal result ~0x41~[ ][ ]0x BE ~0x00 0x69 & 0x55 0x69 | 0x55 8

Practice Problem 1 - Bit-level Operations in C C expressionBinary RepresentationBinary ResultHexadecimal result ~0x41~[ ][ ]0x BE ~0x00~[ ][ ]0x FF 0x69 & 0x55[ ]&[ ][ ]0x 41 0x69 | 0x55[ ]|[ ][ ]0x 7D 9

Practice Problem 2 - Boolean Operations (bit-level and logical operation in C) ExpressionValueExpressionValue x & yx && y x| yx || y ~x | ~y!x ||!y x & !yx && ~y Suppose x and y have byte values 0x66 and 0x39, respectively. Fill in the following table indicating the byte value of the different C expressions: 10

Practice Problem 2 - Boolean Operations (bit-level and logical operation in C) ExpressionValueExpressionValue x & y0x20x && y0x 1 x| y0x7Fx || y0x 1 ~x | ~y0x DF!x ||!y0x 0 x & !y0x 0x && ~y0x 1 Suppose x and y have byte values 0x66 and 0x39, respectively. Fill in the following table indicating the byte value of the different C expressions: 11

Practice Problem 3 Representing Negative Numbers Q1. Using a 8-bit word, find the binary representation of -27. a)Using Sign and Magnitude System b)Using 1’s Complement System c)Using 2’s Complement System 12

Practice Problem 3 Representing Negative Numbers Q1. Using a 8-bit word, find the binary representation of -27. a)Using Sign and Magnitude System N = 27 = 0001, = 1001,1011 b)Using 1’s Complement System N = 27 = 0001, 1011 = 1110, 0100 b)Using 2’s Complement System N* = 1110,

Practice Problem 3 Representing Negative Numbers Q2. Using a 12-bit word, find the binary representation of -27. a)Using Sign and Magnitude System b)Using 1’s Complement System c)Using 2’s Complement System 14

Practice Problem 3 Representing Negative Numbers Q2. Using a 12-bit word, find the binary representation of -27. a)Using Sign and Magnitude System N = 27 = 0000, 0001, = 1000, 0001,1011 (not sign extension from 8 bit) b)Using 1’s Complement System N = 27 = 0000, 0001, 1011 = 1111,1110, 0100 (sign extension from 8 bit) b)Using 2’s Complement System N* = 1111, 1110, 0101 (sign extension from 8 bit) 15

Representing Integers +NPositive int-NSign & Mag2's complement1's complement

Section Integer Representation 17 C data typeBytesMinimumMaximum char unsigned char10255 short (int)2-32,76832,767 unsigned short (int)2065,535 int4-2,147,483,6482,147,483,647 unsigned (int)404,294,967,295 long (int)4-2,147,483,6482,147,483,647 unsigned long (int)404,294,967,295 long long (int)8-9,223,372,036,854,775,8089,223,372,036,854,775,807 Unsigned long long (int)8018,446,744,073,709,551,615 Typical range for C integral data type on 32-bit machine

Section 2.2 Integer Representation 18 Typical range for C integral data type on 64-bit machine C data typeBytesMinimumMaximum char unsigned char10255 short (int)2-32,76832,767 unsigned short (int)2065,535 int4-2,147,483,6482,147,483,647 unsigned (int)404,294,967,295 long (int)8-9,223,372,036,854,775,8089,223,372,036,854,775,807 unsigned long (int)8018,446,744,073,709,551,615 long long (int)8-9,223,372,036,854,775,8089,223,372,036,854,775,807 Unsigned long long (int)8018,446,744,073,709,551,615

Section ASCII Code A character is usually represented as a single byte by using the ASCII code. Strings are represented as arrays of characters terminated by the null character. ASCII – American Standard Code for Information Interchange – 7-bit code (128 ASCII Characters) – Some properties: Codes for digits are consecutive: ‘0’ = 48, ‘1’ =49, etc. Codes for upper case letters are consecutive: ‘A’=65, ‘B’=66, etc. Codes for lower case letters are consecutive: ‘a’=97, ‘b’=98, etc. Maximum value is

ASCII Code A compact table in hex and decimal 20

Section Shift Operations X =[x n-1,x n-2,…, x 1, x 0 ] Left shift: x << k (C expression) – Result: [x n-k-1, x n-k-2, …, x 0, 0,…, 0] – Dropping off the k most significant bits, and filled the right end with k zeros Right shift: x >> k (C expression) – Logical shift: x >> L k Result: [0,…,0,x n-1, x n-2, …, x k ] – Arithmetic shift: x >> A k Result: [x n-1,…, x n-1, x n-1, …, xk] 21

Section Shift Operations x << k is equivalent to multiply by 2 k, x*2 k x >> A k is equivalent to divide by 2 k, x/2 k k < 32 for integer x Many C compilers perform arithmetic right shifts on negative values in which the vacated values are filled with the sign bit. 22

Section – Multiplying by constants A left shift by k bits is equivalent to multiplying by 2 k. Using addition if a small number of 1 bits x * 49 = x * [110001]= x*[ ] = x * [ ] = (x*2 5 )+(x*2 4 )+(x*2 0 )= (x<<5) + (x<<4) +x Using subtraction if a large number of 1 bits in a row x * 78 = x*[ ] = x*[ ] = (x<<6)+(x<<4)-(x<<1) 23

Practice Problem 4 For each of the following values of K, find ways to express x *K using only the specified number of operations, where we consider both addition and subtractions to have comparable cost. 24 KShiftsAdd/SubsExpression

Section Unsigned Encodings There is only one standard way of encoding unsigned integers. Bit vector x = [x w-1, x w-2, …, x 1, x 0 ] with w bits Binary to unsigned number: B2U w (x)=2 w-1  x w-1 +2 w-2  x w-2 +  +2 1  x  x 0 Each integer between 0 and 2 w-1 has a unique representation with w bits. 25

Section Unsigned Encodings Examples: B2U 4 ([0011])=0x2 3 +0x2 2 +1x2 1 +1x2 0 =3 B2U 4 ([1011])=1x2 3 +0x2 2 +1x2 1 +1x2 0 =11 26

Section Unsigned Addition w bits, maximum value is 2 w -1. It might take w+1 bits to represent the value of x+y. Addition is done modulo 2 w. When x+y does not produce the correct result, we say that overflow has occurred. In C, overflow is not detected. How can you test whether adding x and y will produce an overflow? 27

Section Unsigned Addition What is 28

Section Unsigned Addition What is Sol: >2 8 therefore =( )-2 8 =30 29

Unsigned Addition and Substraction 30 Unsigned Addition Unsigned Substraction

Section 2.4 IEEE Floating Point 31 Number of bits Precisionsexpfractotal single double extended

Example: A 6-bit format What is the bias: = 3. How many different values can be represented with 6 bits: 2 6 = 64. How many of these are NaN: 6 How many of these are infinity: 2 How many of these are positive, normalized: 6×4 = 24 How many of these are negative, normalized: 6×4 = 24 How many of values are zero (denormalized): 2 How many of these are denormalized > 0: 3 How many of these are denormalized < 0: 3 32 sexp (3 bits)frac (2 bits)

A 6-bit format (continued) What are the positive normalized values? s = 0; exp = 1, 2, 3, 4, 5, or 6 frac = 00, 01, 10, or 11, corresponding to 1.00, 1.01, 1.10, and 1.11 V = 1.frac * 2 exp – 3 Smallest positive normalized number:

A 6-bit format (continued) Denormalized values: M = frac * 2 -2 = frac/4: 0,.25,.5,.75 value = M 2 -2 = M/4. The values are 0,.0625, 0.125, and Denormalized spacing: Largest denormalized number:

A 6-bit format (continued) Denormalized values: M = frac * 2 -2 = frac/4: 0,.25,.5,.75 value = M × 2 -2 = M/4. The values are 0,.0625, 0.125, and Denormalized spacing: Largest denormalized number:

A 6-bit format (continued) 36 The denormalized values are equally spaced: spacing is The normailzed values are not equally spaced.

Example: Rounding 37 Mode Round-to-even Round-towards-zero Round-down Round-up

Example: Rounding 38 Mode Round-to-even Round-towards-zero1112 Round-down Round-up2223

Rounding Example American Patriot Missile Battery in the first Gulf-War, Feb. 25, 1991, failed to intercept an incoming Iraqi Scud missile. Disaster Result: 28 soldiers killed Failure Analysis by the US General Accounting Office (GAO): – The underlying cause was an impression in a numeric calculation. 39