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

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

CHW 261: Logic Design

Numbering systems. Dr Abu Arqoub

Digital Fundamentals

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

Korea University of Technology and Education

SE311: Design of Digital Systems

Number System. Introduction. Decimal Numbers

MACHINE LEVEL REPRESENTATION OF DATA

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

CHAPTER 2 (b) : AND CODES

Lecture 2: Number Systems

Electronic Data and Instructions

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

Chapter 1 Review of Number Systems

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Computer Arithmetic. Appendix A Fall 2003 Lec.03-58

Lecture (02) Operations on numbering systems

COMP Overview of Tutorial #2

CS & IT Conversions. Magnitude 10,000 1,

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

Number Systems CHAPTER Positional Number Systems

Chapter 2 Data Representations

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Module 2: Computer Arithmetic

Digital Fundamentals

Number representations

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

Binary Codes. Dr. Mudathir A. Fagiri

Divide: Paper & Pencil

Logic and Computer Design Fundamentals. Chapter 1 Digital Computers and Information

Data Representations & Arithmetic Operations

Digital Systems and Binary Numbers

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Chap 1. Digital Computers and Information

Positional Number System

Computer Organization

DIGITAL SYSTEM DESIGN

Number Systems Base r

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

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

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

Number Systems. Both numbers are positive

Introduction to Computers and Programming. Numeric Values

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.

Level ISA3: Information Representation

Number Systems & Encoding

Review of Number Systems

in this web service Cambridge University Press

Digital Systems and Binary Numbers

Digital Systems and Binary Numbers

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

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

Chapter 2. Data Representation in Computer Systems

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

TOPIC: NUMBER SYSTEMS

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

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

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

Introduction to Numbering Systems

World Inside a Computer is Binary

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

Chapter 10 Binary Arithmetics

CMPE223/CMSE222 Digital Logic Design. Positional representation

Lecture 1: Digital Systems and Number Systems

Microcomputers. Outline. Number Systems and Digital Logic Review

Data Representation and Binary Arithmetic. Lecture 2

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

Number Systems and Computer Arithmetic

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

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

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

Arithmetic Processing

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

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

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

COMP 303 Computer Architecture Lecture 6

Lecture 8: Addition, Multiplication & Division

Digital Fundamentals

Chapter 1. Digital Systems and Binary Numbers

NUMBER SYSTEMS AND CODES

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

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Organisasi Sistem Komputer

Chapter 3 DATA REPRESENTATION

Internal Data Representation

QUIZ: Generations of computer technology. Hardware:

ECE 3120 Computer Systems Arithmetic Programming

MC1601 Computer Organization

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

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

Digital Systems COE 202. Digital Logic Design. Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

Advanced Computer Architecture-CS501

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

The. Binary. Number System

Chapter 2 Binary Values and Number Systems

DATA REPRESENTATION. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region. Based on CBSE curriculum Class 11. Neha Tyagi, KV 5 Jaipur II Shift

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

Binary Systems and Codes

Transcription:

Contents Number systems and conversion Binary arithmetic Representation of negative numbers Addition of two s complement numbers Addition of one s complement numbers Binary s Readings Unit.~. UNIT NUMBER SYSTEMS & CONVERSIONS Iris Hui-Ru Jiang Spring Number Systems (/) Number Systems (/) Positional notation: Each digit is multiplied by an appropriate power of base depending on its position in the number The point separates the positive and negative powers of base e.g., decimal (base ) numbers 9.8 = 9x +x +x +x - +8x - (.--): powers of base A positive number N with base (radix) R (positive integer, R>): Examples: Decimal (base ) numbers 9.8 =9x +x +x +x - +8x - Binary (base ) numbers. =x +x +x +x +x - +x - =. Octal (base 8) numbers. 8 =x8 +x8 +x8 +x8 - =. Hexadecimal (base ) numbers N = (a a a a a.a - a - a - ) R = a xr +a xr +a xr +a xr +a xr +a - xr - +a - xr - +a - xr - Base is also called radix Base is indicated as subscript AF =x +x +x = Q: Why do people use the decimal number system?

Common Number Systems Conversion of a Decimal Integer Name Decimal Binary Octal Hexadecimal Radix 8 Digits First positive integers,,,,,,,,8,9 8 9,,,,,,,,,,,,,,,, 8,9,A,B,C,D,E,F 8 9 A B C D E F Convert a decimal integer to base R using division: N = (a n a n-...a a a ) R = a n R n + a n- R n- +... + a R + a R + a N/R = a n R n- + a n- R n- +... + a R + a = Q...remainder a Q /R = a n R n- + a n- R n- +... + a R + a = Q... remainder a Q /R = a n R n- + a n- R n- +... + a = Q...remainder a Continued until we finally obtain.remainder a n e.g., convert to binary remainder = = a (LSB) remainder = = a remainder = = a = remainder = = a remainder = = a remainder = = a (MSB) Conversion of a Decimal Fraction (/) Conversion of a Decimal Fraction (/) Convert a decimal fraction to base R using multiplication: F = (.a - a - a -...a -m ) R = a - R - + a - R - + a - R - +... + a -m R -m FR = a - + a - R - + a - R - +... + a -m R -m+ = a - + F F R = a - + a - R - +... + a -m R -m+ = a - + F F R = a - +... + a -m R -m+ integer = a - + F fraction Continued until we finally obtain a sufficient number of digits e.g., convert. to binary. (). (a - =, MSB) (). (a - =). =. (). (a - =, LSB) 8 Sometimes, the result is a repeating fraction e.g., convert. to binary. (). ().8 (). (). Start repeating! ().. was previously obtained. =. ().8

Conversion between Two Bases (/) Conversion between Two Bases (/) 9 Convert between two bases R and R other than decimal Base R base base R e.g., convert. to base. = x +x +x +x - =. integer fraction. x (). rem. x rem. (). x (). x (). Repeat!. Convert between binary and octal/hexadecimal by inspection. Start at the binary point. Divide bits into groups of three/four, adding s if necessary. Replace each group by an octal/hexadecimal digit. And vice versa Binary octal. =. =. 8 adding s Binary hexadecimal. =. =D.C D C integer fraction. =. =. Binary Arithmetic -- Addition Binary Arithmetic Addition table: + = + = + = + = (and carry to the next column) e.g., add and in binary = = = carries

Binary Arithmetic -- Subtraction Binary Arithmetic -- Multiplication Subtraction table: = = = = (and borrow from the next column) Borrow from the next column have - at the next column = obtain R at the current column e.g., subtract 9 from 9 in binary 9 = 9 = = borrow Multiplication table: x = x = x = x = e.g., multiply by in binary = multiplicand x = multiplier copy of multiplicand if = Binary Arithmetic -- Division 9 AMC8 Is similar to (easier than) decimal division e.g., divide by in binary = quotient divisor = = dividend = remainder A, B, CD. AB AB + CA -CA, DA A A, B, C, D? Remark: decimal

9 AMC8 (Unit test) A, B, CD. AB AB + CA -CA, DA A 8 Representation of Negative Numbers A, B, C, D? Sol: A, B, C, D =,,, 9 B + A = A () => B = B + A = A, B A = A () => A = A C = () => A = C or A = C+ (, ) => C = => A + C = D = + = 9 Addition of two s complement numbers Addition of one s complement numbers Negative Numbers Signed Binary Integers 9 Sign and Magnitude: -bit sign + (n-)-bit magnitude S Magnitude word length: n sign bit: for positive, for negative e.g., sm = +, sm = - Is common for people but awkward for computers s complement: N_ = ( n ) N Complement +N bit-by-bit e.g., + =, _ = s complement: N* = n N = N_ + Complement +N bit-by-bit and then add Or complement all bits to the left of the rightmost e.g., + =, * = +N + + + + + + + + Positive integers (all systems) -N - - - - - - - - -8 Sign and magnitude ---- For word length n, there are n different permutations SM and N_: [+,, +, -,, -] (redundant -) N*: [+,, +,, -8] (- n- ~ + n- -) View the first bit as the sign bit: positive/negative / Word length: n = Negative integers s complement N* ---- s complement N_ ----

Warning: Unsigned or Signed Numbers Addition of Two s Complement Numbers For word length n, there are n different permutations Unsigned: [, n -] Signed SM and N_: [- n- +, + n- -] (redundant -) N*: [- n-, + n- -] e.g., what is?. Add just as if all numbers were positive. Discard the carry from the sign bit Why to discard the carry? (i.e., subtract n ). Add(-A, +B), B > A A* + B = ( n A) + B = n + (B A) n (B A). Add(-A, -B), A+B n- e.g., Add(+A, +B) A+B < n- + + + A* + B* = ( n A) + ( n B) = n + n (A + B) = n + (A + B)* n (A + B)* Add(+A, -B) B > A + - - Add(-A, +B) B > A - + + () Add(-A, -B) A+B n- - - - () Exception: Overflow in Two s Complement Addition of One s Complement Numbers An overflow means out of range of representation When the word length is n bits, the correct representation of a number (including sign) requires more than n bits How to detect overflow? Check sign! (+) + (+) (-) or (-) + (-) (+) e.g., Add(+A, +B) A+B n- + + Wrong answer! Overflow: + requires bits including sign Add(-A, -B) A+B > n- - - () Wrong answer! Overflow: - requires bits including sign End-around carry: Add the carry out back to the rightmost bit Why to take end-around carry? (i.e., subtract n & add ). Add(-A, +B), B > A A_ + B = ( n A) + B = n + (B A) n & + (B A). Add(-A, -B), A+B n- A_ + B_ = ( n A) + ( n B) = n + n (A + B) = n + (A + B)_ n & + (A + B)_ e.g., Add(+A, +B) A+B < n- + + + Add(+A, -B) B > A + - - Add(-A, +B) B > A - + + () Add(-A, -B) A+B n- - - - ()

Exception: Overflow in One s Complement How to detect overflow? Check sign! (+) + (+) (-) or (-) + (-) (+) e.g., Add(+A, +B) A+B n- Add(-A, -B) A+B n- Binary Codes + + Wrong answer! Overflow: + requires bits including sign - - () Wrong answer! Overflow: - requires bits including sign Decimal Digits to Binary Codes Decimal digit 8 9 Input/output interface generally uses decimal numbers How to represent decimal numbers using binary s? Choose elements from binary numbers of bits e.g., 9. BCD:. 8--- --- Excess- -out-of- Weighted Property a.k.a. BCD Weighted = BCD+ Only bits are one For error checking Gray Many options! Only bit changes as counting up/down For analog quantities 8 Warning: Conversion or Coding? Do NOT mix up conversion of a decimal number to a binary number with coding a decimal number with a binary e.g., (This is conversion) (This is coding)

Text to Binary Codes Homework for Unit 9 ASCII American Standard Code for Information Interchange English alphanumeric symbols bits Big- Traditional Chinese characters 8 bits Problems..... Homework # covers Units -- 9 printable characters are numbered to in ASCII Example: 9 AMC8 A, B, CD. AB AB + CA -CA, DA A A, B, C, D?