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

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

Numeric Encodings Prof. James L. Frankel Harvard University

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

Floating Point Arithmetic

COMP2611: Computer Organization. Data Representation

FLOATING POINT NUMBERS

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

Chapter 4. Operations on Data

MIPS Integer ALU Requirements

ECE232: Hardware Organization and Design

COMP Overview of Tutorial #2

CO212 Lecture 10: Arithmetic & Logical Unit

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

Divide: Paper & Pencil

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

MACHINE LEVEL REPRESENTATION OF DATA

Chapter 2 Data Representations

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

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CS 101: Computer Programming and Utilization

Data Representations & Arithmetic Operations

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

Module 2: Computer Arithmetic

Number System. Introduction. Decimal Numbers

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

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

CHW 261: Logic Design

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Floating Point Numbers

Inf2C - Computer Systems Lecture 2 Data Representation

15213 Recitation 2: Floating Point

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

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

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

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

INTEGER REPRESENTATIONS

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

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

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

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

Floating Point Numbers. Lecture 9 CAP

Number Systems. Both numbers are positive

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.

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Introduction to Computer Science-103. Midterm

±M R ±E, S M CHARACTERISTIC MANTISSA 1 k j

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

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

Chapter 3: Arithmetic for Computers

Number Systems and Computer Arithmetic

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

System Programming CISC 360. Floating Point September 16, 2008

Floating Point January 24, 2008

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

3.5 Floating Point: Overview

CHAPTER 1 Numerical Representation

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Floating-point representations

Floating-point representations

CHAPTER 5: Representing Numerical Data

Chapter 5 : Computer Arithmetic

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Number Systems CHAPTER Positional Number Systems

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

Integers and Floating Point

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

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 Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Chapter 3: part 3 Binary Subtraction

Chapter Three. Arithmetic

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

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

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

Digital Fundamentals

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

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

Floating Point Arithmetic

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

M1 Computers and Data

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

Floating Point Numbers

Floating Point Numbers

CPE300: Digital System Architecture and Design

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

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

Organisasi Sistem Komputer

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

A Level Computing. Contents. For the Exam:

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Systems Programming and Computer Architecture ( )

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Chapter 1 Review of Number Systems

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CMPE223/CMSE222 Digital Logic Design. Positional representation

Transcription:

N Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: a n a a a The value of this number is given by: = a n Ka a a a a a 3 K. n 1 n 2 n 3 1 0 1 1 2 b n + a n n 1 0 1 1 b + K a0 b + a 1 b +K Where b is the base of the number system (e.g 2, 8, 10, 16) and a is a digit that range from 0 to b-1 The "radix point" is used to separate the whole number from the fractional portion. In base 10, this is the decimal point; in base 2, the binary point. #1 Lec # 0 Winter99 11-29-99

Number Systems Used in Computers Name of Base Base Set of Digits Example Decimal b=10 a= {0,1,2,3,4,5,6,7,8,9} 255 10 Binary b=2 a= {0,1} %11111111 2 Octal b=10 a= {0,1,2,3,4,5,6,7} 377 8 Hexadecimal b=16 a= {0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F} $FF 16 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 #2 Lec # 0 Winter99 11-29-99

Converting from Decimal to Binary An Example: #3 Lec # 0 Winter99 11-29-99

Algorithm for Converting from Decimal to Any Base Separate the number into its whole number (wholenum) and fractional (fracnum) portions. Convert the whole number portion by repeating the following until "wholenum" is 0: The "digit" resulting from each step is the next digit under the new base starting digit = wholenum % base; with position 0 to the left of the decimal wholenum /= base; point. Convert the fractional portion by repeating the following until "fracnum" is 0 or sufficient precision has been reached: fracnum *= base; digit = (int)base; fracnum -= base; The "digit" resulting from each step is the next digit under the new base starting with position 0 to the right of the decimal point. The final answer is the whole number and fractional computation result separated by a radix point. #4 Lec # 0 Winter99 11-29-99

Algorithm for Converting from Any Base to Decimal Separate the number into its whole number (wholenum) and fractional (fracnum) portions. Convert the whole number portion by starting at the left end advancing to the right where "wholenum" is initially set to 0: wholenum = wholenum * base + digit Example: 3107 16 to decimal 0 +3 = 0 + 3 = 3 (3*16) + 1 = 48 + 1 = 49 (49*16) + 0 = 784 + 0 = 748 (748*16) + 7 = 12544 +7 = 12551 10 Convert the fractional portion by starting at the right end and advancing to the left where "fracnum" is initially set to 0: fracnum = (fracnum + digit) / base; The final answer is the sum of the whole number and fractional parts. #5 Lec # 0 Winter99 11-29-99

Algorithm for Converting Between Arbitrary Bases If the old base is base 10, then use the approach already defined above for converting from base 10 to the new base. If the new base is base 10, then use the approach already defined for converting from any base to base 10. If neither the old or new base is base 10, then: Convert from the current base to base 10. Convert from base 10 to the new base. #6 Lec # 0 Winter99 11-29-99

Binary to Hexadecimal Conversion Separate the whole binary number portion into groups of 4 beginning at the decimal point and working to the left. Add leading zeroes as necessary. Separate the fraction binary number portion into groups of 4 beginning at the decimal (actually binary) point and working to the right. Add trailing zeroes as necessary. Convert each group of 4 to the equivalent hexadecimal digit. Example: 3564.875 10 = 1101 1110 1100.1110 2 = (D * 16 2 ) + (E*16 1 ) + (C*16 0 )+(E*16-1 ) = DEC.E 16 #7 Lec # 0 Winter99 11-29-99

Binary to Octal Conversion Separate the whole binary number portion into groups of 3 beginning at the decimal point and working to the left. Add leading zeroes as necessary. Separate the fraction binary number portion into groups of 3 beginning at the decimal (actually binary) point and working to the right. Add trailing zeroes as necessary. Convert each group of 3 to the equivalent octal digit. Example: 3564.875 10 = 110 111 101 100.111 2 = (6 * 8 3 ) + (7*8 2 ) + (5*8 1 )+(4*8 0 )+(7*8-1 ) = 6754.7 8 #8 Lec # 0 Winter99 11-29-99

Binary Coded Decimal (BCD) Binary Coded Decimal (BCD) is a way to store decimal numbers in binary. This technique uses 4 bits to store each digit from from 0 to 9. For example: 98 10 = 1001 1000 in BCD BCD wastes storage since 4 bits are used to store 10 combinations rather than the maximum possible 16. Arithmetic is more complex to implement in BCD. BCD is frequently used in calculators. Processors may have special instructions to aid BCD calculations. #9 Lec # 0 Winter99 11-29-99

Signed Binary Numbers Sign and Magnitude Representation: For an n-bit binary number: Use the first bit (most significant bit, MSB) position to represent the sign where 0 is positive and 1 is negative. Remaining n-1 bits represent the magnitude which may range from: -2 (n-1) + 1 to 2 (n-1) - 1 This scheme has two representations for 0; i.e., both positive and negative 0: for 8 bits: 00000000, 10000000 Arithmetic under this scheme uses the sign bit to indicate the nature of the operation and the sign of the result, but the sign bit is not used as part of the arithmetic. #10 Lec # 0 Winter99 11-29-99

Signed Binary Numbers Complementary Representation: No sign digit or bit used The complement (negative representation) of an n-digit number is defined as: base n - number To obtain two s Complement representation of an n-bit binary number: or 2 n - number = 2 n - 1 + number + 1 = (1111 111) + number + 1 Invert each bit Add 1 to the result #11 Lec # 0 Winter99 11-29-99

Properties of Two's Complement Numbers X plus the complement of X equals 0. There is one unique 0. Positive numbers have 0 as their leading bit (MSB); while negatives have 1 as their MSB. The range for an n-bit binary number in 2 s complement representation is: from -2 (n-1) to 2 (n-1) - 1 The complement of the complement of a number is the original number. Subtraction is done by addition to the complement of the number. #12 Lec # 0 Winter99 11-29-99

Examples of Two s Complement Addition For n = 8 bits Decimal Binary Hex 11 = 00001011 = 000B + 21 = + 00010101 = + 0015 32 = 00100000 = 0020 Decimal Binary Hex 21 = 00010101 = 0015-11 = + 11110101 = + FFF5 10 = 00001010 = 000A 11 = 00001011 = 000B - 21 = + 11101011 + FFEB - 10 = 11110110 = FFF6-11 = 11110101 = FFF5-21 = + 11101011 = + FFEB - 32 = 1 11100000 = FFE0 #13 Lec # 0 Winter99 11-29-99

Two s Complement Arithmetic Overflow Arithmetic overflow occurs with two's complement number addition if: The operands have the same sign (either positive or negative). The answer has a different sign. The overflow (V) may be represented algebraically by the following equation: V = a n-1 b n-1 s n-1 + a n-1 b n-1 s n-1 Consider 5-bit two's complement, the valid range of numbers is -16 to +15. Consider the following overflow situations: +12 01100 +13 01101 ------ -------- 11001 = -7 Overflow -12 10100-13 10011 ----- --------- 00111 = +7 Overflow #14 Lec # 0 Winter99 11-29-99

What Values Can Be Represented in N Bits? Unsigned: 0 to 2 N - 1 2s Complement: - 2 N-1 to 2 N-1-1 1s Complement: -2 N-1 +1 to 2 N-1-1 BCD 0 to 10 N/4-1 For 32 bits: Unsigned: 0 to 4,294,967,295 2s Complement - 2,147,483,648 to 2,147,483,647 2s Complement - 2,147,483,647 to 2,147,483,647 BCD 0 to 99,999,999 But, what about? Very large numbers? 9,369,396,989,487,762,367,254,859,087,678... or very small number? 0.0000000000000000000000000318579157 #15 Lec # 0 Winter99 11-29-99

Scientific Notation Decimal point Exponent 25-24 5.04 x 10-1.673 x 10 Mantissa Sign, Radix (base) Magnitude Sign, Magnitude #16 Lec # 0 Winter99 11-29-99

Representation of Floating Point Numbers in Single Precision IEEE 754 Standard Value = N = (-1) S X 2 E-127 X (1.M) 0 < E < 255 Actual exponent is: e = E - 127 sign 1 8 23 S E M exponent: excess 127 binary integer added mantissa: sign + magnitude, normalized binary significand with a hidden integer bit: 1.M Example: 0 = 0 00000000 0... 0-1.5 = 1 01111111 10... 0 Magnitude of numbers that can be represented is in the range: 2-126 (1.0) to 2 127 (2-2 -23 ) Which is approximately: 1.8 x 10-38 to 3.40 x 10 38 #17 Lec # 0 Winter99 11-29-99

Representation of Floating Point Numbers in Double Precision IEEE 754 Standard Value = N = (-1) S X 2 E-1023 X (1.M) 0 < E < 2047 Actual exponent is: e = E - 1023 sign 1 11 52 S E M exponent: excess 1023 binary integer added mantissa: sign + magnitude, normalized binary significand with a hidden integer bit: 1.M Example: 0 = 0 00000000000 0... 0-1.5 = 1 01111111111 10... 0 Magnitude of numbers that can be represented is in the range: 2-1022 (1.0) to 2 1023 (2-2 - 52 ) Which is approximately: 2.23 x 10-308 to 1.8 x 10 308 #18 Lec # 0 Winter99 11-29-99

IEEE 754 Special Number Representation Single Precision Double Precision Number Represented Exponent Significand Exponent Significand 0 0 0 0 0 0 nonzero 0 nonzero Denormalized number 1 to 254 anything 1 to 2046 anything Floating Point Number 255 0 2047 0 Infinity 255 nonzero 2047 nonzero NaN (Not A Number) #19 Lec # 0 Winter99 11-29-99

Basic Floating Point Addition Algorithm Addition (or subtraction) involves the following steps: (1) Compute exponent difference: Ye - Xe (2) Align binary point: right shift Xm that many positions to form Xm 2 Xe-Ye (3) Compute sum of aligned mantissas: Xm2 Xe-Ye + Ym (4) If normalization of result is needed, then a normalization step follows: Left shift result, decrement result exponent (e.g., 0.001xx ) or Right shift result, increment result exponent (e.g., 101.1xx ) Continue until MSB of data is 1 (NOTE: Hidden bit in IEEE Standard) (5) If result mantissa is 0, may need to set the exponent to zero by a special step. #20 Lec # 0 Winter99 11-29-99

(1) Start Compare the exponents of the two numbers shift the smaller number to the right until its exponent matches the larger exponent Floating Point Addition (2) Add the significands (mantissas) (3) Normalize the sum, either shifting right and incrementing the exponent or shifting left and decrementing the exponent (4) Overflow or Underflow? Generate exception or return error (5) If mantissa =0 set exponent to 0 Done #21 Lec # 0 Winter99 11-29-99

Logical Operations on Binary Values: AND, OR AND, *, A B A AND B 0 0 0 0 1 0 1 0 0 1 1 1 Bitwise AND operation of two numbers Example: A AND B A 11011010 AND B 01001101 = 01001000 OR, +, A B A OR B 0 0 0 0 1 1 1 0 1 1 1 1 Bitwise OR operation of two numbers Example: A OR B A 11011010 OR B 01001101 = 11011111 #22 Lec # 0 Winter99 11-29-99

Logical Operations on Binary Values: XOR, NOT Exclusive OR, EOR, XOR, A B A XOR B 0 0 0 0 1 1 1 0 1 1 1 0 Bitwise XOR operation of two numbers Example: A XOR B NOT, ~, X Inverts or complements a bit Example: A = 1101100 A = 0010011 A 1101101 0 XOR B 01001101 = 10010111 #23 Lec # 0 Winter99 11-29-99