INTEGER REPRESENTATIONS

Similar documents
IEEE Standard 754 Floating Point Numbers

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

COMP2611: Computer Organization. Data Representation

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Numeric Encodings Prof. James L. Frankel Harvard University

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

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

Floating Point Arithmetic

Floating Point. What can be represented in N bits? 0 to 2N-1. 9,349,398,989,787,762,244,859,087, x 1067

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

Chapter 4: Data Representations

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

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

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

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

Finite arithmetic and error analysis

15213 Recitation 2: Floating Point

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

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

ECE232: Hardware Organization and Design

IEEE-754 floating-point

Floating Point Numbers

Chapter Three. Arithmetic

Representing and Manipulating Floating Points. Jo, Heeseung

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

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

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

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

World Inside a Computer is Binary

Co-processor Math Processor. Richa Upadhyay Prabhu. NMIMS s MPSTME February 9, 2016

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

Inf2C - Computer Systems Lecture 2 Data Representation

IEEE 754 Floating-Point Format

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

Representing and Manipulating Floating Points

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

3.5 Floating Point: Overview

Floating Point Numbers. Lecture 9 CAP

CHW 261: Logic Design

Programming. Definition. 2's Complement Representation for Signed Integers

M1 Computers and Data

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point Arithmetic

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

IEEE Floating Point Numbers Overview

Module 2: Computer Arithmetic

COMP2121: Microprocessors and Interfacing. Number Systems

Integers and Floating Point

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

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

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

CS 101: Computer Programming and Utilization

CO212 Lecture 10: Arithmetic & Logical Unit

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Signed umbers. Sign/Magnitude otation

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

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

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

Computer Organization: A Programmer's Perspective

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Data Representation Floating Point

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

Floating Point January 24, 2008

Number Systems. Both numbers are positive

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

Representing and Manipulating Floating Points

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

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

CHAPTER 1 Numerical Representation

Foundations of Computer Systems

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

Floating Point Numbers

Floating Point Numbers

Real Numbers. range -- need to deal with larger range, not just [not just -2^(n-1) to +2^(n-1)-1] - large numbers - small numbers (fractions)

MACHINE LEVEL REPRESENTATION OF DATA

System Programming CISC 360. Floating Point September 16, 2008

Representing and Manipulating Floating Points

Data Representation Floating Point

Harry H. Porter, 2006

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

IEEE Standard for Floating-Point Arithmetic: 754

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

Chapter 3: Arithmetic for Computers

CS101 Lecture 04: Binary Arithmetic

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

FLOATING POINT NUMBERS

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

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

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

Giving credit where credit is due

8/30/2016. In Binary, We Have A Binary Point. ECE 120: Introduction to Computing. Fixed-Point Representations Support Fractions

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Giving credit where credit is due

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

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

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

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

Transcription:

INTEGER REPRESENTATIONS Unsigned Representation (B2U). Two s Complement (B2T). Signed Magnitude (B2S). Ones Complement (B2O). scheme size in bits (w) minimum value maximum value B2U 5 0 31 B2U 8 0 255 B2U 12 0 4095 B2U 16 0 65535 B2T 5-16 15 B2T 8-128 127 B2T 12-2048 2047 B2T 16-32768 32767 B2O 5-15 15 B2O 8-127 127 B2O 12-2047 2047 B2O 16-32767 32767 B2S 5-15 15 B2S 8-127 127 B2S 12-2047 2047 B2S 16-32767 32767 Remember 2^15 2^14 2^13 2^12 2^11 2^10 2^9 2^8 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 1. Convert 10111 base 2 to decimal for the following decoding schemes B2U = 23 B2T = - 9 B2O = - 8 B2S = - 7 2. Convert the number 95 base 10 to the following 8- bit encoding schemes 0101 1111 all the same B2U B2S B2T B2O 3. Convert the number 130 base 10 to the following 8- bit encoding schemes 1000 0010 for B2U; rest=overflow B2U B2S B2T B2O 4. Convert the number - 223 base 10 to the following 16- bit encoding schemes B2U no negative #s B2T 0xFF21 B2O 0xFF20 B2S 0x80DF

SIGNED/UNSIGNED #include <stdio.h> void main() % gcc - o sign2unsign sign2unsign.c { sign2unsign.c In function main int x; sign2unsign.c17 warning overflow in implicit constant for (x = - 8; x < 8; x++) conversion printf("xd = %d xu = %u xx = %.4x\n", x, (unsigned short) x, (unsigned short) x); printf("\n"); for (x = - 8; x < 8; x++) printf("xd = %d xu = %u xx = %.8x\n", x, x, x); x = 65528; printf("\n65528 in hex = %.8x\n",x); short a = 0xFFFF + 1; printf("\n0xffff + 1 = %d\n",a); } xd = - 8 xu = 65528 xx = fff8 xd = - 7 xu = 65529 xx = fff9 xd = - 6 xu = 65530 xx = fffa xd = - 5 xu = 65531 xx = fffb xd = - 4 xu = 65532 xx = fffc xd = - 3 xu = 65533 xx = fffd xd = - 2 xu = 65534 xx = fffe xd = - 1 xu = 65535 xx = ffff xd = 0 xu = 0 xx = 0000 xd = 1 xu = 1 xx = 0001 xd = 2 xu = 2 xx = 0002 xd = 3 xu = 3 xx = 0003 xd = 4 xu = 4 xx = 0004 xd = 5 xu = 5 xx = 0005 xd = 6 xu = 6 xx = 0006 xd = 7 xu = 7 xx = 0007 xd = - 8 xu = 4294967288 xx = fffffff8 xd = - 7 xu = 4294967289 xx = fffffff9 xd = - 6 xu = 4294967290 xx = fffffffa xd = - 5 xu = 4294967291 xx = fffffffb xd = - 4 xu = 4294967292 xx = fffffffc xd = - 3 xu = 4294967293 xx = fffffffd xd = - 2 xu = 4294967294 xx = fffffffe xd = - 1 xu = 4294967295 xx = ffffffff xd = 0 xu = 0 xx = 00000000 xd = 1 xu = 1 xx = 00000001 xd = 2 xu = 2 xx = 00000002 xd = 3 xu = 3 xx = 00000003 xd = 4 xu = 4 xx = 00000004 xd = 5 xu = 5 xx = 00000005 xd = 6 xu = 6 xx = 00000006 xd = 7 xu = 7 xx = 00000007 65528 in hex = 0000fff8 0xFFFF + 1 = 0

Decimal 8-bit 2 s comp Addition 23 +45 === 68 00010111 00101101 0 0111111 carry 00010111 00101101 0 01000100 =68? yes 23-45 === -22 00010111 11010011 0 0010111 carry 00010111 11010011 0 11101010 =-22? yes 100 +45 === 145 01100100 00101101 0 1101100 carry 01100100 00101101 0 10010001 =145? NOOOOOOOOOO -45-23 === -68 11010011 11101001 1 1000011 carry 11010011 11101001 1 10111100 =-68? yes What is OVERFLOW for B2T values??? When the carry- in is not equal to the carry- out (seen in green above). That is P+P à N i.e. a positive value plus a positive value that results in a negative value N+N à P i.e. a negative value plus a negative value that results in a positive value

An example http//pages.cs.wisc.edu/~cs354-2/cs354/karen.notes/flpt.apprec.html Put the decimal number 64.2 into the IEEE standard single precision floating point representation. Step 1 Get a binary representation for 64.2. To do this, get unsigned binary representations for the stuff to the left and right of the decimal point separately. 64 is 1000000.2 can be gotten using the algorithm decimal down.2 x 2 = 0.4 0 à keep the whole portion here and carry the.4 x 2 = 0.8 0.8 x 2 = 1.6 1.6 x 2 = 1.2 1.2 x 2 = 0.4 0 now this whole pattern (0011) repeats..4 x 2 = 0.8 0.8 x 2 = 1.6 1.6 x 2 = 1.2 1 so a binary representation for.2 is.001100110011... Putting the halves back together again 64.2 is 1000000.0011001100110011... Step 2 Normalize the binary representation. (make it look like scientific notation) 1.000000 00110011... x 2^6 Step 3 6 is the true exponent. For the standard form, it needs to be in 8-bit, biased-127 representation. 6 + 127 ----- 133 133 in 8-bit, unsigned representation is 1000 0101 This is the bit pattern used for e in the standard form. Step 4 The mantissa/significand stored (f) is the stuff to the right of the radix point in the normalized form. We need 23 bits of it. 000000 00110011001100110 Put it all together (and include the correct sign bit) s e f 0 10000101 00000000110011001100110

0b 0100 0010 1000 0000 0110 0110 0110 0110 0x 4 2 8 0 6 6 6 6 Computers represent real values in a form similar to that of scientific notation. Consider the value 1.23 x 10^4 The number has a sign (+ in this case) The significand (1.23) is written with one non-zero digit to the left of the decimal point. The base (radix) is 10. The exponent (an integer value) is 4. It too must have a sign. There are standards which define what the representation means, so that across computers there will be consistency. Note that this is not the only way to represent floating point numbers, it is just the IEEE standard way of doing it. Here is what we do The representation has three fields ---------------------------- s e f ---------------------------- S is one bit representing the sign of the number E is an 8-bit biased integer representing the exponent F is an unsigned integer The decimal value represented is where s E (-1) x F x 2 E = e bias à e = E + bias F = ( f/(2^n) ) + 1 à f = (F-1)*2 n For single precision representation, n = 23 and bias = 127 For double precision representation (a 64-bit representation), n = 52 (there are 52 bits for the mantissa field) bias = 1023 (there are 11 bits for the exponent field) Now, what does all this mean? s, e, f all represent fields within a representation. Each is just a bunch of bits. s is just a sign bit. 0 for positive, 1 for negative. This is the sign of the number. e is an exponent field. The e field is a biased-127 integer representation. So, the true exponent represented is (e - bias).

The radix for the number is ALWAYS 2. Note Computers that did not use this representation, like those built before the standard, did not always use a radix of 2. For example, some IBM machines had radix of 16. f is the mantissa (significand). It is in a somewhat modified form. There are 23 bits available for the mantissa. It turns out that if floating point numbers are always stored in their normalized form, then the leading bit (the one on the left, or MSB) is ALWAYS a 1. So, why store it at all? It gets put back into the number (giving 24 bits of precision for the mantissa) for any calculation, but we only have to store 23 bits. This MSB is called the hidden bit.

To sum up, the following are the corresponding values for a given representation Sign Exponent (e) Float Values (b = bias) Fraction (f) Value 0 00..00 00..00 +0 0 00..00 0 11..10 11..11 XX..XX Positive Denormalized Real 0.f 2 (-b+1) Positive Normalized Real 1.f 2 (e-b) 0 11..11 00..00 +Infinity 0 11..11 0 11..11 01..11 10..00 11..11 SNaN QNaN 1 00..00 00..00-0 1 00..00 1 11..10 11..11 XX..XX Negative Denormalized Real -0.f 2 (-b+1) Negative Normalized Real -1.f 2 (e-b) 1 11..11 00..00 -Infinity 1 11..11 1 11..11 01..11 10..00 11.11 SNaN QNaN Special Values IEEE reserves exponent field values of all 0s and all 1s to denote special values in the floating-point scheme. Zero As mentioned above, zero is not directly representable in the straight format, due to the assumption of a leading 1 (we'd need to specify a true zero mantissa to yield a value of zero). Zero is a special value denoted with an exponent field of zero and a fraction field of zero. Note that -0 and +0 are distinct values, though they both compare as equal. Denormalized If the exponent is all 0s, but the fraction is non-zero (else it would be interpreted as zero), then the value is a denormalized number, which does not have an assumed leading 1 before the binary point. Thus, this represents a number (-1) s 0.f 2-126, where s is the sign bit and f is the fraction. For double precision, denormalized numbers are of the form (-1) s 0.f 2-1022. From this you can interpret zero as a special type of denormalized number. Infinity The values +infinity and -infinity are denoted with an exponent of all 1s and a fraction of all 0s. The sign bit distinguishes between negative infinity and positive infinity. Being able to denote infinity as a specific value is useful because it allows operations to continue past overflow situations. Operations with infinite values are well defined in IEEE floating point. Not A Number The value NaN (Not a Number) is used to represent a value that does not represent a real number. NaN's are represented by a bit pattern with an exponent of all 1s and a non-zero fraction. There are two categories of NaN QNaN (Quiet NaN) and SNaN (Signalling NaN). A QNaN is a NaN with the most significant fraction bit set. QNaN's propagate freely through most arithmetic operations. These values pop out of an operation when the result is not mathematically defined. An SNaN is a NaN with the most significant fraction bit clear. It is used to signal an exception when used in operations. SNaN's can be handy to assign to uninitialized variables to trap premature usage. Semantically, QNaN's denote indeterminate operations, while SNaN's denote invalid operations.