Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

Similar documents
IEEE 754 Floating-Point Format

Basic Assignment and Arithmetic Operators

IEEE 754 Floating-Point Format

COMP2611: Computer Organization. Data Representation

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

DS: CS Computer Sc & Engg: IIT Kharagpur 1. roblem Set III. Goutam Biswas

15213 Recitation 2: Floating Point

Floating Point Arithmetic

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement

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

Name Roll No. Section

INTEGER REPRESENTATIONS

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

ECE232: Hardware Organization and Design

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

MACHINE LEVEL REPRESENTATION OF DATA

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

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

Computer Systems Programming. Practice Midterm. Name:

Numeric Encodings Prof. James L. Frankel Harvard University

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

CS 101: Computer Programming and Utilization

CS16 Exam #1 7/17/ Minutes 100 Points total

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

IEEE Standard for Floating-Point Arithmetic: 754

BSM540 Basics of C Language

Floating Point Numbers

Floating Point Numbers

Computer System and programming in C

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

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

CS101 Introduction to computing Floating Point Numbers

Floating Point Numbers. Lecture 9 CAP

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

Characters, Strings, and Floats

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

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

Lecture 3. More About C

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

Representing and Manipulating Floating Points. Jo, Heeseung

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

Representing and Manipulating Floating Points

These are reserved words of the C language. For example int, float, if, else, for, while etc.

C Program Reviews 2-12

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

COMP2121: Microprocessors and Interfacing. Number Systems

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

COMP Overview of Tutorial #2

Floating Point Numbers

(2 7 *0) + (2 6 *1) + (2 5 *1) + (2 4 *0) + (2 3 *1) + (2 2 *1)+(2 1 *0)+(2 0 *1)

World Inside a Computer is Binary

CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

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

Data Representation in Computer Memory

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination

Computer Systems C S Cynthia Lee

ESC 101N: Fundmentals of Computing ( IInd Semester) Mid Sem II Examination PM, Monday 7th March, 2011

Final Labs and Tutors

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

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

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Time (self-scheduled): Location Schedule Your Exam: What to bring:

Inf2C - Computer Systems Lecture 2 Data Representation

Slides adopted from T. Ferguson Spring 2016

Chapter 3. Information Representation

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

Chapter 7. Basic Types

C Formatted IO. Day16.C. Young W. Lim. December 9, 2017

Chapter 3. Fundamental Data Types

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

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

Fundamentals of Programming

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

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

Fundamental of Programming (C)

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Data Representation Floating Point

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

IEEE-754 floating-point

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College January 27, 2015

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

1. The keyword main in C language is used for

Representing and Manipulating Floating Points

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

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

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

Chapter Three. Arithmetic

Programming and Data Structures

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

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

Transcription:

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 1 Tutorial Programming & Data Structure: CS 11001 Section - 1/A DO NOT POWER ON THE MACHINE Department of Computer Science and Engineering I.I.T. Kharagpur Spring Semester: 2009-2010 (27.01.2010)

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 2 Download Download the file tut270110.ps from Programming & Data Structures... of http://www.facweb.iitkgp.ernet.in/ goutam View the file using the command kghostview & or ggv &

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 3 Tutorial III What is IEEE 754 floating-point representation?

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 4 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 s exponent significand/mantissa 1 bit 8 bits 23 bits Single Precession 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 s exponent significand/mantissa 1 bit 11 bits 20 bits significand (continued) 32 bits Double Precession

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 5 Single Precession Data Fields Data Type Exponent Significand 0 0 0 0 nonzero ± denormal number 1-254 anything ± normalized number 255 0 ± 255 nonzero N an (not a number)

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 6 Double Precession Data Fields Data Type Exponent Significand 0 0 0 0 nonzero ± denormal number 1-2046 anything ± normalized number 2047 0 ± 2047 nonzero N an (not a number)

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 7 Single Precession Normalized Number Let the sign bit (31) be s, the exponent (30-23) be e and the mantissa (significand) (22-0) be m. The valid range of the exponent is 1 to 254 (if e is treated as an unsigned number). The exponent (e) is biased by 127 i.e. the actual value of the exponent is e 127. This gives a range: 2 1 127 = 2 126 to 2 254 127 = 2 127.

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 8 Single Precession Normalized Number The normalized significand is 1.m (binary dot). One is not present explicitly. The sign bit s = 1 is a -ve number and s = 0 is a +ve number. The final value of a normalized number is ( 1) s 1.m 2 e 127

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 9 Single Precession Denormal Number The interpretation of a denormal number is different. The content of the exponent part (e) is zero and the significand part (m) is non-zero. The value of a denormal number is ( 1) s 0.m 2 126 There is no implicit one in the significand.

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 10 Tutorial III.1 1. What is the representation of 27.75 in IEEE-754 single precession format? 2. What is the representation of +27.7? 3. What is the largest magnitude of a single precession normalized number? 4. What is the smallest magnitude of a single precession normalized number? 5. Answer the last two questions for denormal

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 11 numbers. 6. What is the value stored as a result of 1.0/0.0?

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 12 Tutorial III.2 Write a C program that computes the sum up to the n th term of the series, where n is an input. 1 2 + 1 + 1 4 + 1 2 + 1 6 + 1 3 + + 1 2k + 1 k + + 1 α. where 1 α = 1 m 1 2m if n = 2m, if n = 2m 1.

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 13 Tutorial III.3

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 14 What will be printed (a)? #include <stdio.h> int main() //./pds/lect/prog/temp2.c { printf("0%%10 = %d\n", 0%10); printf("4%%10 = %d\n", 4%10); printf("10%%4 = %d\n", 10%4); printf("-10%%4 = %d\n", -10%4); return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 15 What will be printed (b)? #include <stdio.h> int main() //./pds/lect/prog/temp3.c { int n = 4 ; float a = 2.5 ; char c = a ; // ASCII value 97 printf("%d*%f = %f\n", n, a, n*a); printf("%d*%f+%c = %f\n",n,a,c,n*a+c); return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 16 What will be printed (c)? #include <stdio.h> int main() //./pds/lect/prog/temp4.c { printf("1/3*30.0=%f\n", 1/3*30.0); return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 17 What will be printed (d)? #include <stdio.h> int main() //./pds/lect/prog/temp14.c { int n = 2147483647; printf("n+1: %d\n", n+1) ; return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 18 What will be printed (e)? #include <stdio.h> int main() //./pds/lect/prog/temp8.c { float a=1.0e-5, b=1.0e+5, c; c = a+b ; printf("%e + %e = %e\n", a, b, c); return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 19 What will be printed (f)? #include <stdio.h> int main(){ // temp32.c float a = 1.7 ; } if(a == 1.7) printf("equal\n") ; else printf("unequal\n") ; return 0 ;

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 20 What will be printed (g)? #include <stdio.h> int main() //./pds/lect/prog/temp9.c { int n = 10, m ; printf("enter an integer: "); scanf("%d", &m); // Enter zero printf("n/m: %d\n", n/m); return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 21 What will be printed (h)? #include <stdio.h> #include <math.h> int main() //./pds/lect/prog/temp10.c { float n = 10.0, m, r ; printf("enter a number: "); scanf("%f", &m); // Enter zero printf("n/m: %f\n", r = n/m); printf("atan(%f) = %f\n", r, atan(r)); return 0 ; }

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 22 Tutorial III.6 Write a C program to print the ASCII values of a character in decimal, hex and octal notation. Char Decimal Hex Oct a 97 0x61 0141 A 65 0x41 0101