CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Similar documents
COMP Overview of Tutorial #2

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

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

CHW 261: Logic Design

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

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Digital Fundamentals

Number System. Introduction. Decimal Numbers

Number Systems. Both numbers are positive

MACHINE LEVEL REPRESENTATION OF DATA

Chapter 10 Binary Arithmetics

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Chapter 3: part 3 Binary Subtraction

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

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

Korea University of Technology and Education

Digital Systems and Binary Numbers

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

Number Systems CHAPTER Positional Number Systems

MC1601 Computer Organization

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

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

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

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

EE 109 Unit 6 Binary Arithmetic

Advanced Computer Architecture-CS501

Chapter 4. Operations on Data

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

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

CHAPTER 1 Numerical Representation

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

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

Numeric Encodings Prof. James L. Frankel Harvard University

Chapter 4 Arithmetic Functions

Numerical Representations On The Computer: Negative And Rational Numbers

Chapter 1 Review of Number Systems

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

CMPE223/CMSE222 Digital Logic Design. Positional representation

Number representations

Numerical Representations On The Computer: Negative And Rational Numbers

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

Number Systems Base r

Level ISA3: Information Representation

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

CS & IT Conversions. Magnitude 10,000 1,

World Inside a Computer is Binary

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

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

Chapter 3: Arithmetic for Computers

Computer Organization

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Lecture 2: Number Systems

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,...

Inf2C - Computer Systems Lecture 2 Data Representation

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

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

Chapter 2: Number Systems

Digital Logic Lecture 2 Number Systems

CS 101: Computer Programming and Utilization

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

T02 Tutorial Slides for Week 2

Number Systems and Number Representation

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

Binary Systems and Codes

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

Introduction to Computer Science-103. Midterm

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design


Chapter 2 Bits, Data Types, and Operations

Lecture (02) Operations on numbering systems

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

Divide: Paper & Pencil

CO212 Lecture 10: Arithmetic & Logical Unit

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

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

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

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

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

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

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

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

Objectives. Connecting with Computer Science 2

Microcomputers. Outline. Number Systems and Digital Logic Review

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

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

Digital Systems and Binary Numbers

Chapter 2 Bits, Data Types, and Operations

Introduction to Computers and Programming. Numeric Values

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

Arithmetic Processing

SE311: Design of Digital Systems

Binary Representations and Arithmetic

The type of all data used in a C++ program must be specified

Organisasi Sistem Komputer

Numbering systems. Dr Abu Arqoub

Fundamentals of Programming Session 2

Transcription:

CHAPTER V-1 CHAPTER V CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

CHAPTER V-2 NUMBER SYSTEMS RADIX-R REPRESENTATION Decimal number expansion 73625 10 = ( 7 10 4 ) + ( 3 10 3 ) + ( 6 10 2 ) + ( 2 10 1 ) +( 5 10 0 ) Binary number representation 10110 2 = ( 1 2 4 ) + ( 0 2 3 ) + ( 1 2 2 ) + ( 1 2 1 ) + ( 0 2 0 ) = 22 10 Hexadecimal number representation 3E4B8 16 = ( 3 16 4 ) + ( 14 16 3 ) + ( 4 16 2 ) + ( 11 16 1 ) + ( 8 16 0 ) = 255160 10

CHAPTER V-3 NUMBER SYSTEMS DECIMAL REPRESENTATION -NUMBER REPRES. Radix-10 Representation 73625.4385 10 10 2 10 3 10 4 10 5 10 4 10 3 10 2 10 1 10 0 10 1 10 5... 0 7 3 6 2 5. 4 3 8 5 0... 73625.4385 10 = ( 7 10 4 ) + ( 3 10 3 ) + ( 6 10 2 ) + ( 2 10 1 ) + ( 5 10 0 ) + ( 4 10 1 ) + ( 3 10 2 ) + ( 8 10 3 ) + ( 5 10 4 )

CHAPTER V-4 NUMBER SYSTEMS BINARY REPRESENTATION -NUMBER REPRES. -DECIMAL REPRES. Radix-2 Representation 10110.0011 2 2 2 2 3 2 4 2 5 2 4 2 3 2 2 2 1 2 0 2 1 2 5... 0 1 0 1 1 0. 0 0 1 1 0... MSB LSB 10110.0011 2 = ( 1 2 4 ) + ( 0 2 3 ) + ( 1 2 2 ) + ( 1 2 1 ) +( 0 2 0 ) = + ( 0 2 1 ) + ( 0 2 2 ) + ( 1 2 3 ) +( 1 2 4 ) 22.1875 10

CHAPTER V-5 NUMBER SYSTEMS OCTAL REPRESENTATION -NUMBER REPRES. -DECIMAL REPRES. -BINARY REPRES. Radix-8 Representation 26516.1731 8 8 2 8 3 8 4 8 5 8 4 8 3 8 2 8 1 8 0 8 1 8 5... 0 2 6 5 1 6. 1 7 3 1 0... 26516.1731 8 = ( 2 8 4 ) + ( 6 8 3 ) + ( 5 8 2 ) + ( 1 8 1 ) +( 6 8 0 ) + ( 1 8 1 ) + ( 7 8 2 ) + ( 3 8 3 ) +( 1 8 4 ) = 11598.24 10

CHAPTER V-6 NUMBER SYSTEMS HEXADECIMAL REPRES. -DECIMAL REPRES. -BINARY REPRES. -OCTAL REPRES. Radix-16 Representation 19AD6.F411 16 16 2 16 3 16 4 16 5 16 4 16 3 16 2 16 1 16 0 16 1 16 5... 0 1 9 A D 6. F 4 1 1 0... 19AD6.F411 16 = ( 1 16 4 ) + ( 9 16 3 ) + ( A 16 2 ) + ( D 16 1 ) + ( 6 16 0 ) + ( F 16 1 ) + ( 4 16 2 ) + ( 1 16 3 ) +( 1 16 4 ) 105174.95 10

CHAPTER V-7 NUMBER SYSTEMS BINARY <-> HEXADECIMAL -BINARY REPRES. -OCTAL REPRES. -HEXADECIMAL REPRES. BINARY <-> HEXADECIMAL 0000 2 = 0 16 0001 2 = 1 16 0010 2 = 2 16 0011 2 = 3 16 0100 2 = 4 16 0101 2 = 5 16 0110 2 = 6 16 0111 2 = 7 16 1000 2 = 8 16 1001 2 = 9 16 1010 2 = 10 (A 16 ) 1011 2 = 11 (B 16 ) 1100 2 = 12 (C 16 ) 1101 2 = 13 (D 16 ) 1110 2 = 14 (E 16 ) 1111 2 = 15 (F 16 ) BINARY -> HEXADECIMAL Group binary by 4 bits from radix point Examples: 0111 1011 2 = 7B 16 7 B 10 1010 0110.1100 01 2 = 2A6.C4 16 2 A 6 C 4

CHAPTER V-8 NUMBER SYSTEMS BINARY <-> OCTAL -BINARY REPRES. -OCTAL REPRES. -BINARY<->HEXADECIMAL BINARY <-> OCTAL 000 2 = 0 8 001 2 = 1 8 010 2 = 2 8 011 2 = 3 8 100 2 = 4 8 101 2 = 5 8 110 2 = 6 8 111 2 = 7 8 Examples: BINARY -> OCTAL Group binary bits by 3 from LSB 10 100 110 2 = 246 8 2 4 6 10 101 111 011.011 11 2 = 2573.36 8 2 5 7 3 3 6

CHAPTER V-9 NUMBER SYSTEMS BINARY -> DECIMAL -OCTAL REPRES. -BINARY<->HEXADECIMAL -BINARY<->OCTAL Perform radix-2 expansion Multiply each bit in the binary number by 2 to the power of its place. Then sum all of the values to get the decimal value. Examples: 10111 2 = ( 1 2 4 ) + ( 0 2 3 ) + ( 1 2 2 ) + ( 1 2 1 ) + ( 1 2 0 ) = 23 10 10110.0011 2 = ( 1 2 4 ) + ( 0 2 3 ) + ( 1 2 2 ) + ( 1 2 1 ) +( 0 2 0 ) = + ( 0 2 1 ) + ( 0 2 2 ) + ( 1 2 3 ) +( 1 2 4 ) 22.1875 10

CHAPTER V-10 NUMBER SYSTEMS DECIMAL -> BINARY -BINARY<->HEXADECIMAL -BINARY<->OCTAL -BINARY->DECIMAL Integer part: Modulo division of decimal integer by 2 to get each bit, starting with LSB. Fraction part: Multiplication decimal fraction by 2 and collect resulting integers, starting with MSB. Example: Convert 41.828125 10 41 mod 2 = 1 LSB 20 mod 2 = 0 10 mod 2 = 0 5 mod 2 = 1 2 mod 2 = 0 1 mod 2 = 1 MSB 0.828125 2 = 1.65625 0.65625 2 = 1.3125 0.3125 2 = 0.625 0.625 2 = 1.25 0.25 2 = 0.5 0.5 2 = 1.0 MSB LSB Therefore 41.828125 10 = 101001.110101 2

CHAPTER V-11 NUMBER SYSTEMS FLOATING POINT NUMBERS -BINARY<->HEXADECIMAL -BINARY->DECIMAL -DECIMAL->BINARY Floating point numbers can be represented with a sign bit, a fraction (often referred to as the mantissa), and an exponent. Example 1: 267.426 = 0.267426 10 3, where the sign is negative, the fraction is 0.267426 and the exponent is 3. Example 2: 0101011.1001 = 0.1010111 2 6, where the sign is positive, the fraction is 0.1010111, and the exponent is 0110. Sample IEEE Floating-Point Formats 32-bit s e f 1 8 23 64-bit s e f 1 11 52

CHAPTER V-12 BINARY NUMBERS UNSIGNED INTEGER -DECIMAL->BINARY -POWERS OF 2 -FLOATING POINT The range for an n-bit radix- r unsigned integer is n 1 [ 0, r 10 ] Example: For a 16-bit binary unsigned integer, the range is [ 0, 2 16 1] = [ 0, 65535] which has a binary representation of 0000 0000 0000 0000 = 0 0000 0000 0000 0001 = 1 0000 0000 0000 0010 = 2... 1111 1111 1111 1110 = 65534 1111 1111 1111 1111 = 65535

CHAPTER V-13 BINARY NUMBERS SIGNED INTEGERS (1) BINARY NUMBERS -UNSIGNED INTEGERS The range for an n-bit radix- r signed integer is rn 1 10 n 1 1 [, r 10 ] The most-significant bit is used as a sign bit, where 0 indicates a positive integer and 1 indicates a negative integer. Example: For a 16-bit binary signed integer, the range is [ 2 16 1, 2 16 1 1] = [ 32768, 32767]

CHAPTER V-14 BINARY NUMBERS SIGNED INTEGERS (2) BINARY NUMBERS -UNSIGNED INTEGERS -SIGNED INTEGERS There are a number of different representations for signed integers, each which has its own advantage Signed-magnitude representation: 1010 0001 0110 1111 Signed-1 s complement representation: 1101 1110 1001 0000 Signed-2 s complement representation: 1101 1110 1001 0001 The above examples are all the same number, 8559 10.

CHAPTER V-15 BINARY NUMBERS SIGNED-MAGNITUDE BINARY NUMBERS -UNSIGNED INTEGERS -SIGNED INTEGERS The signed-magnitude binary integer representation is just like the unsigned representation with the addition of a sign bit. For instance, using 8-bits, the number can be represented as the 7-bit magnitude of using 6 10 6 10 000 0110 and then the sign bit appended to the MSB to form 1000 0110

CHAPTER V-16 BINARY NUMBERS RADIX COMPLEMENTS BINARY NUMBERS -UNSIGNED INTEGERS -SIGNED INTEGERS -SIGNED-MAGNITUDE The radix complement, or r s complement, of an integer representation for an n-digit integer is defined as r n 10 number 10 The diminished radix complement, or (r - 1) s complement, of an integer representation for an n-digit integer is defined as ( r n 10 1 10 ) number 10 Example: Find the r s and (r - 1) s complement for 3764 10 r s complement (r - 1) s complement 10 5 3764 = 96236 ( 10 5 1) 3764 = 96235

CHAPTER V-17 BINARY NUMBERS 1 S COMPLEMENT BINARY NUMBERS -SIGNED INTEGERS -SIGNED-MAGNITUDE -RADIX COMPLEMENTS The 1 s complement (diminished radix complement) binary integer representation for an n-bit integer is defined as ( 2 n 10 1 10 ) number 10 In essence, this takes the positive version of the number and flips all of the bits. For instance, using 8-bits, the number can be represented as the 8-bit positive number using 6 10 6 10 0000 0110 and then each of the bits flipped to form the 1 s complement 1111 1001

CHAPTER V-18 BINARY NUMBERS 2 S COMPLEMENT BINARY NUMBERS -SIGNED-MAGNITUDE -RADIX COMPLEMENTS -1 S COMPLEMENT The 2 s complement (radix complement) binary integer representation for an n-bit integer is defined as 2 n 10 number 10 In essence, this takes the 1 s complement and adds one. For instance, using 8-bits, the number can be represented as the 8-bit positive number using 6 10 6 10 0000 0110 and then each of the bits flipped to form the 1 s complement 1111 1001 and then add 1 to form the 2 s complement 1111 1010

CHAPTER V-19 BINARY NUMBERS SIGNED EXAMPLES BINARY NUMBERS -RADIX COMPLEMENTS -1 S COMPLEMENT -2 S COMPLEMENT Below are some examples for the signed binary numbers using 6 bits. Decimal Signed-magnitude 1 s complement 2 s complement 0 00 0000 00 0000 00 0000 1 00 0001 00 0001 00 0001-1 10 0001 11 1110 11 1111 5 00 0101 00 0101 00 0101-5 10 0101 11 1010 11 1011 12 00 1100 00 1100 00 1100-12 10 1100 11 0011 11 0100 15 00 1111 00 1111 00 1111-15 10 1111 11 0000 11 0001 16 01 0000 01 0000 01 0000-16 11 0000 10 1111 11 0000 Notice that all representations are the same for positive numbers!!!!

CHAPTER V-20 BINARY ARITHMETIC UNSIGNED ADDITION BINARY NUMBERS -1 S COMPLEMENT -2 S COMPLEMENT -SIGNED EXAMPLES Unsigned binary addition follows the standard rules of addition. Examples + 1111 0100 Carries 0011 1011 0111 1010 + 0000 0010 Carries 1011 1001 0100 0101 1011 0101 1111 1110 1111 0000 Carries 1111 1001 + 0100 1000 1 0100 0000 + 1110 0000 0000.0000 Carries 0101 1000 1001.1001 0011 0011 0100.01 1000 1011 1101.1101

CHAPTER V-21 BINARY ARITHMETIC UNSIGNED SUBTRACTION BINARY NUMBERS BINARY ARITHMETIC -UNSIGNED ADDITION Unsigned binary subtraction follows the standard rules. Examples - 0000 0000 Borrows 1111 1001 0100 1000-1000 1000 Borrows 1011 1001 0100 0101 1011 0001 0111 0100-1000 0000 Borrows 0011 1011 0111 1010-0100 1110 1000.1000 Borrows 0101 1000 1001.1001 0011 0011 0100.01 1100 0001 0010 0101 0101.0101

CHAPTER V-22 BINARY ARITHMETIC SIGNED ADDITION BINARY NUMBERS BINARY ARITHMETIC -UNSIGNED ADDITION -UNSIGNED SUBTRACT. Signed-magnitude Add magnitudes if signs are the same, give result the sign Subtract magnitudes if signs are different. Absence or presence of an end borrow determines the resulting sign compared to the augend. If negative, then a 2 s complement correction must be taken. 2 s complement Add the numbers using normal addition rules. Carry out bit is discarded. 1 s complement Easiest to convert to 2 s complement, perform the addition, and then convert back to 1 s complement. This is done as follows: Add 1 to each integer, add the integers, subtract 1 from the result

CHAPTER V-23 BINARY ARITHMETIC SIGNED SUBTRACTION BINARY ARITHMETIC -UNSIGNED ADDITION -UNSIGNED SUBTRACT. -SIGNED ADDITION Typically want to do addition or subtraction of A and B as follows. SUM = A + B DIFFERENCE = A B If we use 2 s complement, we can make life easy on us since addition and subtraction are done in the same manner: with addition only!!! A subtraction can be re-reprepresented as follows. SUM = A + ( B) Or in general any two numbers can be added as follows. SUM = ( ± A) + ( ± B)

CHAPTER V-24 BINARY ARITHMETIC SIGNED MATH EXAMPLE BINARY ARITHMETIC -UNSIGNED ADDITION -UNSIGNED SUBTRACT. -SIGNED ADDITION Subtraction of signed numbers can best be done with 2 s complement. Performed by taking the 2 s complement of the subtrahend and then performing addition (including the sign bit). Example: - 59 122 0011 1011 = = - 0111 1010 2 s complement discard carry out 0 0111 1100 Carries 0011 1011 standard addition + 1000 0110 1100 0001 = -(0011 1111) = -63 2 s complement