Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Similar documents
CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Number Systems CHAPTER Positional Number Systems

Number System. Introduction. Decimal Numbers

COMP Overview of Tutorial #2

CHW 261: Logic Design

CS & IT Conversions. Magnitude 10,000 1,

Introduction to Computers and Programming. Numeric Values

Divide: Paper & Pencil

Digital Fundamentals

Module 2: Computer Arithmetic

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Signed Binary Numbers

Chapter 3: Arithmetic for Computers

Chapter 2: Number Systems

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

CHAPTER 2 Data Representation in Computer Systems

Chapter 4. Operations on Data

CHAPTER 2 Data Representation in Computer Systems

Number Systems. Both numbers are positive

MACHINE LEVEL REPRESENTATION OF DATA

Chapter 2 Data Representations

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

Data Representations & Arithmetic Operations

Number representations

BINARY SYSTEM. Binary system is used in digital systems because it is:

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

CMPE223/CMSE222 Digital Logic Design. Positional representation

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

Digital Systems and Binary Numbers

Lecture 2: Number Systems

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Advanced Computer Architecture-CS501

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

CS 101: Computer Programming and Utilization

Chapter 2. Data Representation in Computer Systems

Inf2C - Computer Systems Lecture 2 Data Representation

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

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

COMPUTER ARITHMETIC (Part 1)

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

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

Introduction to Computer Science-103. Midterm

T02 Tutorial Slides for Week 2

MC1601 Computer Organization

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

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

Internal Data Representation

CO212 Lecture 10: Arithmetic & Logical Unit

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

CS101 Lecture 04: Binary Arithmetic

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Objectives. Connecting with Computer Science 2

Number Systems and Their Representations

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

Computer Organisation CS303

Lecture 8: Addition, Multiplication & Division

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

CHAPTER 2 Number Systems

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

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

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Arithmetic Processing

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

Chapter 5 : Computer Arithmetic

2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

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

CHAPTER 1 Numerical Representation

Basic Arithmetic (adding and subtracting)

COMP2611: Computer Organization. Data Representation

Chapter 1 Review of Number Systems

Representation of Numbers

Octal and Hexadecimal Integers

Floating Point Arithmetic

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

Lecture (02) Operations on numbering systems

Computer Arithmetic Ch 8

MIPS Integer ALU Requirements

Computer Arithmetic Ch 8

CS 121 Digital Logic Design. Chapter 1. Teacher Assistant. Hadeel Al-Ateeq

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

Korea University of Technology and Education

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

D I G I T A L C I R C U I T S E E

Level ISA3: Information Representation

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Data Representation 1

The. Binary. Number System

Digital Systems and Binary Numbers

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Signed umbers. Sign/Magnitude otation

Number Systems and Computer Arithmetic

Transcription:

Chapter 2 Positional number systems A positional number system represents numeric values as sequences of one or more digits. Each digit in the representation is weighted according to its position in the number. The weights increase towards the left by a constant factor called the base or radix (the Latin word for root ). The positions corresponding to integral weights ( ) are separated from the positions corresponding to fractional weights (< ) by the radix point (. ). 0 2 + 0 + 0 0. 0 + 0 2 365.24 0 = 3 00 + 6 0 + 5. 2 0. + 4 0.0 Generalised for any radix R: R 2 R R 0. R R 2 stu.vw r = s + t + u + v + w Some commonly used bases are: R = 2 8 0 6 name binary octal decimal hexadecimal A radix R representation uses R distinct digits, starting with 0. Binary uses two digits, 0 and. Octal uses eight digits, 0 through 7. Hexadecimal requires 6 digits and uses the first ten decimal digits ( 0 to 9 ) followed by the first six letters ( A to F, representing digit values 0 through 5). Arithmetic performed on a single digit produces results modulo R (ignoring carry). Arithmetic on a -digit number produces results modulo R. The representations of nr + k and k are the same, and nr 0. 2. Signed number representations binary octal decimal hexadecimal 0000 0 0 0 000 000 2 2 2 00 3 3 3 000 4 4 4 00 5 5 5 00 6 6 6 0 7 7 7 000 0 8 8 00 9 9 00 2 0 A 0 3 B 00 4 2 C 0 5 3 D 0 6 4 E 7 5 F The sign of a number indicates whether or not it is negative. The magnitude (or absolute value ) of a number x, written x, is the distance of that number from 0. x, x 0 x = x, x < 0 A signed number representation encodes both the sign and the magnitude of a value as an unsigned number, using a fixed number of radix-r digits. 2.. Signed magnitude 4

A negative value x is represented as R/2 + x. The most significant digit encodes the sign; if it is R/2 or greater then the number is negative. Subtracting R/2 from a negative number recovers its magnitude. With signed magnitude representations, non-negative values are represented as their unsigned value. There are two representations for zero (+0 and 0), and +0+ 0= 0. Additive arithmetic operators and comparisons are more complex than with other representations. Division is simpler than with other representations [Sec. 3.4], and signed magnitude is used to represent the mantissa of floating-point numbers. 7-bit magnitude signed magnitude decimal binary value R =0, =2 R =2, =8 49 49 00000 20 20 000000 5 5 0000 0 0000000 0 50 0000000 5 000000 5 65 000 20 70 00000 49 99 0000 7-bit magnitude 0 0 0 0 0 x 4 = 4 0 0 0 0 - x 4 = -4 positive sign negative sign 2..2 Biased Any number x is represented as x + k (where k is a constant), allowing values in the range [ k, R k] to be represented. Subtracting k from the stored number recovers its signed value. Typically k = R /2 so that zero falls in the middle of the range of representable values. o non-negative value is represented as its unsigned value. So, while there is only one representation for 0, it is not the same as unsigned 0. Arithmetic operators are difficult to implement, and 0+0 6= 0(because k+k 6= k, mod R, except when k =0which is not useful). Biased representations are used to store the exponent of floating-point numbers, where only relative magnitude of exponents is important. 2..3 Diminished radix complement A negative number x is represented by R x. As with signed magnitude representation, the most significant digit encodes the sign of the number, which is negative if the S digit is R/2 or greater. R x can be formed by individually inverting each digit x i in x. The inverse of a digit d is R d [Fig. 2.]. (Inverting a binary digit just exchanges 0 and, and is often called flipping the bit.) This works because = = R i (R x i ) (individually inverted digits x i ) R i R i= X R i R i R i = R R 0 R i x i R i x i X R i x i = R x. ( the diminished radix complement of x) 5

digit 0 2 3 4 5 6 7 8 9 A B C D E F inverted binary digit 0 inverted octal digit 7 6 5 4 3 2 0 inverted decimal digit 9 8 7 6 5 4 3 2 0 inverted hexadecimal digit F E D C B A 9 8 7 6 5 4 3 2 0 Figure 2.: Inverse digits ( negative sign digits highlighted) If R is fixed then the dimished radix complement can be called the (R ) s complement. For decimal it is the nine s complement, and for binary the one s complement. Using a fixed number of digits (arithmetic modulo R ), a number x and its diminished radix complement x sum to zero. Unfortunately there are two representations for zero (+0 6= 0) and x + x = 0(modR ). Worse, 0+ 0= (modr ). Diminished radix complement is seldom used as a representation for storing signed numbers. Computing the diminished radix complement in hardware is, however, very efficient. It is used in the ALU to implement binary arithmetic [Sec. 3.2] and logic [Sec. 5..] operations. 9 s and s complement value decimal binary 49 49 00000 20 20 000000 5 5 0000 0 0000000 0 99 98 0 5 84 0000 20 79 00 49 50 000 2..4 Radix complement A negative number x is represented by R x. This can be formed by taking the diminshed radix complement of x and adding to it. The most significant digit still encodes the sign of the number, which is negative if the S digit is R/2 or greater. Using a fixed number of digits (arithmetic modulo R ), a number x and its radix complement x sum to zero. There is only one representation of zero, and it has non-negative sign. Addition and subtraction of any two signed values using radix complement representation yields the correct result (modulo R ) provided the result does not exceed the range of values that can be represented in digits [Secs. 3., 3.2]. Adding when negating increases the range of representable negative values by one, making it asymmetric value decimal binary 0 s and 2 s complement ([ R,R ]). The most negative value ( R ) therefore cannot be negated, since the result is one larger than the 28 27 0 50 00000 maximum representable positive value. 49 49 00000 For a radix R, the dimished radix complement is often 20 20 000000 called the R s complement. For decimal it is the ten s complement, and for binary the two s complement. 0 0000000 5 5 0000 The final addition of could cause every digit to change, as carries are propagated from least to most significant 99 digit [Sec. 3.], but this addition can often be peformed implicitly with no additional overhead [Sec. 3.2]. 20 80 000 5 85 000 Two s complement is the most common representation 49 5 00 50 50 000 for both storing and performing arithmetic on signed binary 27 000000 numbers in digital computers. 28 0000000 6

2.2 Radix conversion Converting between binary and either octal or hexadecimal is trivial. To convert to/from octal (base 8=2 3 ), consider groups of three bits. To convert to/from hexadecimal (base 6 = 2 4 ), consider groups of four bits. (Between octal and hexadecimal, go through binary.) octal 7 5 3 binary 0 0 0 0 hexadecimal F 5 9 To convert a number to a representation in an arbitrary base, consider the integral and fractional parts separately, and extract one digit at a time. Let x R be a number in radix R representation. ultiplying x by R moves the radix point one position to the right (shifts the number one position to the left). Dividing x by R moves the radix point one position to the left (shifts the number one position to the right). Therefore: To extract the rightmost digit d from an integer x R, divide x by R and the remainder is d. To extract the leftmost digit d from a fraction x R, multiply x by R and the integral part of the result is d. Repeated application of these operations will convert a number into its representation in any base [Algs. 2., 2.2, 2.3]. Algorithm 2. Converting an integer into an arbitrary radix representation input: an integer n and a radix R procedure ITEGERTORADIX(n, R) q n div R. x div y is the integer quotient of x y d n mod R. x mod y is the remainder of x y if q 6= 0then ITEGERTORADIX(q, R) end if output digit d. output all digits to the left of d Algorithm 2.2 Converting a fraction into an arbitrary radix representation input: a fraction n and a radix R procedure FRACTIOTORADIX(n, R) repeat n n R d bnc. bxc is the integer part of x output digit D n n d. the fractional part of n until n =0 7

Algorithm 2.3 Converting a number into an arbitrary radix representation input: a number n and a radix R procedure UBERTORADIX(n, R) ITEGERTORADIX(bnc,R). output the integer part of n output radix point. FRACTIOTORADIX(n bnc,r). output the fractional part of n 2.3 Binary numbers Binary numbers have radix 2. When signed, they are usually stored using two s complement representaion. Binary arithmetic [Ch. 3] is usually peformed using two s complement representation, with one s complement being useful in a few situations [Sec. 3.4]. 2.3. Two s complement decimal conversions To convert a two s complement number to decimal, sum the weighted contributions of each bit (as if it were unsigned) but use (2 ) for the most significant bit (instead of 2 ). (2 7 ) 2 6 2 5 2 4 2 3 2 2 2 2 0 28 64 32 6 8 4 2 0 0 0 0 64 + 8 + 4 + 2 = 78 0 0 0 28 + 64 + 8 + 4 + 2 = 50 To convert a negative decimal to two s complement, add 2 to it, convert the resulting non-negative number to binary, and then set the sign bit to. The above follow from converting just the sign bit to a non-negative magnitude (by taking its two s complement) and then negating the result to obtain its positional weight. x = (2 2 )= 2 2.3.2 Width conversions A -bit unsigned binary number x is widened to >bits by setting bits x [,] to 0; this is called zero-extending x. arrowing from bits to bits is achieved by discarding bits x [,], with possible loss of information; this is called truncating x. A -bit signed binary number x is widened to >bits by copying the sign bit x into bits x [,] ; this is called sign-extending x. arrowing from bits to bits is achieved by discarding bits x[ :], with possible loss of information including arbitrary change of sign. unsigned zero-extend 0 0 0 000 widening signed =3 sign-extend 0 =3 0 unsigned 0 0 00 truncate 0 narrowing signed =29 0 truncate =3 0 00 0 0 0000 00 0 0 0000 =+5 =+5 0 0 0000 00 0 0 0000 00 =+9 =-7 8