S09 Recitation #1 Jernej Barbic (S06) Revised: Alex Gartrell (S09)

Slides:



Advertisements
Similar presentations
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
Advertisements

15213 Recitation Fall 2014 Section A, 8 th September Vinay Bhat.
University of Washington Today Topics: Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
Recitation # Section F Spring 2006 Jernej Barbic.
Floating Point Numbers
Unsigned and Signed Numbers. Hexadecimal Number 217A 16 Position Digits A Value = 2x x x16 + Ax1 = 2x x x16.
The Binary Number System
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computer Architecture
Floating Point Representations CDA 3101 Discussion Session 02.
1 Information Representation in Computer Lecture Nine.
1 Carnegie Mellon Welcome to recitation! : Introduction to Computer Systems 3 rd Recitation, Sept. 10, 2012 Instructor: Adrian Trejo (atrejo) Section.
Floating Point Numbers
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Floating Point Representations
Lecture 6. Fixed and Floating Point Numbers
Programming and Data Structure
Floating Point CSE 238/2038/2138: Systems Programming
Floating Point Borrowed from the Carnegie Mellon (Thanks, guys!)
Floating Point Numbers
CS 105 “Tour of the Black Holes of Computing!”
Number Representation
2.4. Floating Point Numbers
Floating Point Representations
CSCI206 - Computer Organization & Programming
Recitation 4&5 and review 1 & 2 & 3
Floating Point Math & Representation
Lecture 9: Floating Point
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Chapter 3 Data Storage.
Numbers in a Computer Unsigned integers Signed magnitude
Floating Point Number system corresponding to the decimal notation
IEEE floating point format
CS/COE0447 Computer Organization & Assembly Language
Computer Architecture & Operations I
CS 367 Floating Point Topics (Ch 2.4) IEEE Floating Point Standard
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
Data Structures Mohammed Thajeel To the second year students
What to bring: iCard, pens/pencils (They provide the scratch paper)
Lecture 10: Floating Point, Digital Design
Topic 3d Representation of Real Numbers
Number Representations
CS201 - Lecture 5 Floating Point
CSCI206 - Computer Organization & Programming
CS 105 “Tour of the Black Holes of Computing!”
How to represent real numbers
How to represent real numbers
CS 105 “Tour of the Black Holes of Computing!”
Floating Point Arithmetic August 31, 2009
CS 105 “Tour of the Black Holes of Computing!”
Chapter 2 Representing and Manipulating Information
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Recitation 5 – 2/19/01 Outline
Numbers representations
CS213 Floating Point Topics IEEE Floating Point Standard Rounding
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
CS 286 Computer Architecture & Organization
Overview Fractions & Sign Extension Floating Point Representations
CS 105 “Tour of the Black Holes of Computing!”
Chapter 2 Representing and Manipulating Information
Number Representations
Lecture 9: Shift, Mult, Div Fixed & Floating Point
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

15-213-S09 Recitation #1 Jernej Barbic (S06) Revised: Alex Gartrell (S09)

Little Endian to Big Endian 32-bit unsigned integer: 0x257950B2 n = 37 * 224 + 121 * 216 + 80 * 28 + 178 Little Endian: Big Endian:

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

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

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

Datalab Example - Max Return the max of 2 ints (x, y) 2 cases: Different signs – look at sign of x Same sign – look at sign of x-y int max (int x, int y) { int sub = x - y; int signcomp = x ^ y; // compare the signs // if signs are similar, take the sign of x-y, if not, take the sign of x. //This will be 1 if y is greater, 0 otherwise int mask = ((signcomp) & x) | (~signcomp & sub)) >> 31; return (mask & y) | (~mask & x); }

Datalab Example - Least Bit Pos Return a mask of the least bit position of n Take a binary number x (1011...010..0) Flip the bits (0100...101...1) Add 1 to it (0100...110...0) Only 1's occupying the same position between each the new     number and original are in the lowest bit position int leastBitPos(int x) {      return x & (~x + 1); }

2’s complement: some examples 0x7FFFFFFF = 231-1 // largest 32-bit int 0xFFFFFFFF = -1 0xFFFFFFFE = -2 0x800000000 = -231 // smallest 32-bit int 0x800000001 = -231 + 1

Simple 8-bit Integer Example Some simple, positive examples:     0b0001 0110      = 128(0) + 64(0) + 32(0) + 16(1) + 8(0) + 4(1) + 2(1) + 1(0)     = 16 + 4 + 2     = 22     53     = 32 + 16 + 4 + 1     = 128(0) + 64(0) + 32(1) + 16(1) + 8(0) + 4(1) + 2(0) + 1(1)     = 0011 0101

Signed 8-bit Integer Examples Using    -x = (~x) + 1     -14     = -(14)     = -(8(1) + 4(1) + 2(1) + 1(0))     = -(0000 1110)     = ~(0000 1110) + 1     = (1111 0001) + 1     = 1111 0010 Using negative sign bit (for numbers close to tMin)     -120     = -128(1) + 8(1)     = 1000 1000

Other Signed 8-bit Integer Examples 12 = 63 = 72 = -10 = -100 =

Other Signed 8-bit Integer Examples 12 = 0000 1100 63 = 0011 1111 72 = 0100 1000 -10 = ~(0000 1010) + 1 = 1111 0101 + 1 = 1111 0110 -100 = -128 + 28 = 1001 1100

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

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

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

8-bit Floating Point Example 8-bit floating point (1 sign, 3 exponent, 4 fraction)     bias = 2^(3 - 1) - 1 = 3 encode 13/16 sign bit = 0 (13/16 >= 0) 13/16 = 13 x 2^(-4)     = 1101 x 2^(-4)     = 1.1010 x 2^(-1) (remove the 1 because it's normalized) exponent = -1 + bias = 2 = 010 result = 0 010 1010

8-bit Floating Point Example 8-bit floating point (1 sign, 3 exponent, 4 fraction)     bias = 2^(3 - 1) - 1 = 3 encode -3/32 sign bit = 1 (-3/32 < 0) 3/32 = 3 x 2^(-5)     = 0b11 x 2^(-5)     = 1.1 x 2^(-4) Note: Lowest possible exponent is -2                                     Must denormalize     = .011 x 2^(-2) exponent = 0 (denormalized) result = 1 000 0110

Other 8-bit Floating Point Examples 10/4 = -3 = -10 = 1/64 =

Other 8-bit Floating Point Examples 10/4 = 0 100 0100 -3 = 1 100 1000 -10 = 1 110 0100 1/64 = 0 000 0001

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

Version Control - Do It Version Control allows you to maintain old versions of your source code, potentially saving you if you were to do something like rm -rf * Good SVN tutorial:     http://artis.imag.fr/~Xavier.Decoret/resources/svn/index.html Note:     repoDir=`pwd` #of working dir     Path to repo is svn+ssh://unix.andrew.cmu.edu/${repoDir} Example:     svn+ssh://unix.andrew.cmu.edu/afs/andrew.cmu.edu/usr17/agartrel/svn/15-410