Recitation #2 15-213 Section F Spring 2006 Jernej Barbic.

Slides:



Advertisements
Similar presentations
Computer Organization and Architecture Tutorial 6 Kenneth Lee.
Advertisements

Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
1 C Fundamentals - I Math 130 Lecture # 2 B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Sp05: With discussion.
Lecture - 2 Number systems and computer data formats
15213 Recitation Fall 2014 Section A, 8 th September Vinay Bhat.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
Carnegie Mellon Floating Point : Introduction to Computer Systems – Recitation January 24, 2011.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.
Floating Point Numbers. CMPE12cCyrus Bazeghi 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
Floating Point Numbers
Computer Science A 14: 3/4. Computing with numbers - Precision - Representation - Computing with numbers - Example.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
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.
Computing Systems Basic arithmetic for computers.
Computer Architecture
Fundamental of Computer Architecture By Panyayot Chaikan November 01, 2003.
Data Representation - Part I. Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen.
Lecture Set 4 Data Types and Variables Part A – Introduction Numeric Data Types.
Data Representation in Computer Systems
Floating Point Representations CDA 3101 Discussion Session 02.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems October 14, 2013.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Integer and Fixed Point P & H: Chapter 3
Computer Architecture Lecture 22 Fasih ur Rehman.
1 Information Representation in Computer Lecture Nine.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
火雨辰 homeWork1.
1 Carnegie Mellon Welcome to recitation! : Introduction to Computer Systems 3 rd Recitation, Sept. 10, 2012 Instructor: Adrian Trejo (atrejo) Section.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 14, 2013 Marjorie Carlson Section A.
Numbers in Computers.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 13, 2014 Lou Clark.
CS 3843 Computer Organization Prof. Qi Tian Fall 2013
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
Data Lab: Manipulating Bits
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Lecture 6. Fixed and Floating Point Numbers
MIPS Arithmetic is 32 bits
Number Representation
Floating Point Representations
CSCI206 - Computer Organization & Programming
Recitation 4&5 and review 1 & 2 & 3
Floating Point Math & Representation
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Tokens in C Keywords Identifiers Constants
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
S09 Recitation #1 Jernej Barbic (S06) Revised: Alex Gartrell (S09)
INTRODUCTION c is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs.
Number Representations
CSCI206 - Computer Organization & Programming
How to represent real numbers
Lectures on Numerical Methods
Data Types and Variables Part A – Introduction Numeric Data Types
How are negative and rational numbers represented on the computer?
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
COMS 161 Introduction to Computing
Topic 3d Representation of Real Numbers
Number Representations
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Recitation # Section F Spring 2006 Jernej Barbic

Little Endian to Big Endian 32-bit unsigned integer: n = 37 * * * Little Endian: Big Endian:

Little Endian to Big Endian Little Endian: Big Endian: unsigned int LE2BE(unsigned int x) { unsigned int result = ( x << 24 ) | ( (x << 8) & (0xFF << 16) ) | ( (x >> 8) & (0xFF > 24) & 0xFF ) ; return result; }

If-then-else if (condition) expression1; else expression2;

If-then-else ( condition & expression1) | (~condition & expression2) Rewrite as: if (condition) expression1; else expression2;

If-then-else if (condition) expression1; else expression2; ( condition & expression1) | (~condition & expression2) Rewrite as: int abs(int x) { int sign = x >> 31; // makes either all one or all zero int neg_x = ~x + 1; // computes –x (2’s complement) * return (sign & neg_x) | (~sign & x); // if-then-else }

2’s complement: general rule = b = b b b

2’s complement: some examples 0x0 = 0 0x1 = 1 0x7FFFFFFF = // largest 32-bit int 0xFFFFFFFF = -1 0xFFFFFFFE = -2 0x = // smallest 32-bit int 0x =

Floating point Single precision: Double precision: k = 11, n= 52 Note: exponent boundary is NOT aligned with byte boundary e.g. 0xFF7FFFFF has lowest exponent bit zero (is normalized v.)

Floating point decision diagram Is e == 0 ? x = (-1) s * 2 1-Bias * 0.M Is e all 1’s ? Is M == 0 ? YES NO YES Is s==0 ? ++ -- NaN x = (-1) s * 2 e-Bias * 1.M NO ++ YES NO denormalized normalized Bias = 2 k E E

Example 1/4 = 1.0 * 2 -2 s=0, e = -2 + Bias = 125, M = 0 representation = 3E800000

-7/8 = x 2 -1 s = 1 e = -1 + Bias = 126 M = 1100…0 representation = 0xBF Example #2

Example #3 -17 = x 2 4 s = 1 e = 4 + Bias = 131 M = …0 representation = 0xC

Integer as signed int vs float =(int) 0x =(float) 0x4A550C84 Any correlation in bit patterns?

Integer as signed int vs float =(int) 0x354321: = 2 21 * 1.c So, we also have = 2 21 * 1.c Hence: s=0, e=21+Bias=148, M=c00 c length(c)=21

Integer as signed int vs float =(int) 0x354321: =(float) 0x4A550C84: equal bitstrings

Good coding style Consistent indentation Avoid long sequences of commands without a comment Each source file should have an appropriate header Have a brief comment at the beginning of each function

Quiz #1 Location: blackboard Open book, open notes, closed computer Available: today at 4:30pm Duration: 30 minutes You must start it by tomorrow 11:30pm Covers: all material so far Don’t close your browser while taking the quiz If there are problems, please professor