Chapter 2 Number Systems + Codes. Overview Objective: To use positional number systems To convert decimals to binary integers To convert binary integers.

Slides:



Advertisements
Similar presentations
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
Advertisements

CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
Sistemas Digitais I LESI - 2º ano Lesson 2 - Number Systems U NIVERSIDADE DO M INHO E SCOLA DE E NGENHARIA Prof. João Miguel Fernandes
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Data Representation ICS 233
ECE 331 – Digital System Design
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Number Systems and Arithmetic
Number Systems Lecture 02.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Digital Design: Principles and Practices Chapter 2 Number Systems and Codes.
Data Representation – Binary Numbers
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
ECE 3110: Introduction to Digital Systems Review #1 (Chapter 1,2)
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
CE1111 :Digital Logic Design lecture 01 Introduction Dr. Atef Ali Ibrahim.
IKI Data Types & Representations Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Dr. Ahmed Telba EE208: Logic Design Lecture# 1 Introduction & Number Systems.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Topic 1 – Number Systems. What is a Number System? A number system consists of an ordered set of symbols (digits) with relations defined for addition,
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Digital Design Basics Analog vs Digital Why we need digital? Reproducibility, economy, programmability… Digital Devices Gates, FFs Combinational, sequential.
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Chapter 1 Number Systems Digital Electronics. Topics discussed in last lecture Digital systems Advantages of using digital signals over analog. Disadvantages.
NUMBER SYSTEMS AND CODES. CS Digital LogicNumber Systems and Codes2 Outline Number systems –Number notations –Arithmetic –Base conversions –Signed.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
ECE 2110: Introduction to Digital Systems
Integer Operations Computer Organization and Assembly Language: Module 5.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
1 Digital Logic Design (41-135) Chapter 5 Number Representation & Arithmetic Circuits Younglok Kim Dept. of Electrical Engineering Sogang University Spring.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
CPE 201 Digital Design Lecture 2: Digital Systems & Binary Numbers (2)
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 1 Introduction Digital Systems Digital systems: computation, data processing, control, communication, measurement - Reliable, Integration.
Data Representation COE 308 Computer Architecture
Addition and Subtraction
Positional Number Systems Decimal, Binary, Octal and Hexadecimal Numbers Wakerly Section
Data Representation ICS 233
Number Systems and Codes (parte 1)
Data Representation.
CHAPTER 1 : INTRODUCTION
Chapter 2 Data Types and Representations
Wakerly Section 2.4 and further
Digital Electronics & Logic Design
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Data Representation COE 308 Computer Architecture
Presentation transcript:

Chapter 2 Number Systems + Codes

Overview Objective: To use positional number systems To convert decimals to binary integers To convert binary integers to decimals To represent binary integers in 3 forms: –Sign magnitude –1’s complement –2’s complement To reprensent number in octal (base 8) and hexadecimal numbers and convert them to decimal and binary numbers To understand various computer codes

Overview Two types of representations of information: Numeric information -Positional number system -Conversion between number systems -Operation on number systems (add, substract …) Non numeric information -Codes - Properties of codes

Overview Real life Data Numeric data (125.5 : a price Nonnumeric data (John : a name ) Representation of data in Computer or digital circuits : string of 0’s and 1’s Correspondance or Representation

Positional Number Systems (PNS) PNS – a number is represented by a string of digits. Each digit position is weighted by a power of the base or radix. Example: Decimal PNS, in base 10 digit position i is weighted by 10 i =9       .0001 General Form: Base or Radix = 10 D : d p-1 d p-2 d p-3 … d 2 d 1 d 0. d -1 d -2 …d -n D = d p-1.10 p-1 + d p-2.10 p-2 +…+ d d d d … + d -n.10 -n p -1 D =  d i.10 i i=-n I. Representation of numerical information d i is a decimal digit

Positional Number Systems (PNS) General Form: Base or Radix = 2 D : b p-1 b p-2 b p-3 … b 2 b 1 b 0. b -1 b -2 …b -n D = b p-1.2 p-1 + b p-2.2 p-2 +…+ b b b b … + b -n.2 -n p -1 D =  b i.2 i i=-n b i is a binary digit I. Representation of numerical information

Summary of PNS Decimal is natural (we count in base 10) - (Radix or Base 10 ) digits  {0,1,…,8,9} Binary is used in digital system - (Radix or Base 2 ) digits  {0,1} Octal is used for representing multibits (group of 3 bits) numbers in digital systems. - (Radix or Base 8=2 3 ) digits  {0,1,…,6,7} Hexadecimal is used for representing multibits (group of 4 bits) numbers in digital systems - (Radix or Base 16=2 4 ) digits  {0,1,…9,A,B,…,F} I. Representation of numerical information

Summary of PNS (…) Dec Binary Oct Hex 000 (000)0 (0000) (001)1 (0001) 2102 (010)2 (0010) 3113 (011)3 (0011) (100)4 (0100) ( 101)5 (0101) (110)6 (0110) (111)7 (0111) ( )8 (1000) ( )9 (1001) ( )A (1010) ( )B (1011) ( )C (1100) ( )D (1101) ( )E (1110) ( )F (1111) ( )10 ( ) I. Representation of numerical information

Conversions From any base r ---> Decimal Use base 10 arythmetic to expand : p -1 D =  d i.r i (r is the base and di are the digits) i=0 Two solutions can be used to do this : Polynomial expansion D = d p-1.r p-1 + d p-2.r p-2 +…+ d 1.r 1 + d 0.r 0 Examples : = = = CE8 16 = = = = I. Representation of numerical information

Conversions From any base r ---> Decimal Iterative multiplication (Expansion of D) D can be written as : ((….((d p-1).r + d p-2).r +…+d 2 ).r + d 1 ).r + d 0 Examples : = ((3).16+ 1) ) = (49) = Good for programming I. Representation of numerical information

Conversions From Decimal ---> Any base r Successive divisions of D by r yield the digits from the least to the most significant bit. Remember that D can be written in base r as : D = d p-1.r p-1 + d p-2.r p-2 +…+ d 1.r + d 0. = ((….((d p-1).r + d p-2).r +…+d 2 ).r + d 1 ).r + d 0 D/r -----> quotient D1 = (….((dp-1).r + dp-2).r +…+d 2 ).r + d 1 remainder d0 D1/r -----> quotient D2 = (….((dp-1).r + dp-2).r +… d3).r+d 2 ) remainder d1 D2/r -----> quotient D3 = (….((dp-1).r + dp-2).r +…+d 3 ) remainder d2 And so on ….. I. Representation of numerical information

Conversions From Decimal ---> Any base r Example : conversion of 179 from Base 10 -> Base LSB MSB weight Successive divisions by = I. Representation of numerical information

Conversions From Decimal ---> Any base r Example : conversion of 467 from Base 10 -> Base LSB MSB 467 weight successive divisions = I. Representation of numerical information

Other Conversions From Binary ---> Octal/Hex Conversion by substitution –Binary to Oct : Starting from rightmost bit, make groups of 3 bits and convert each group to base = 100/011/001/110 = / 3 / 1 / 6 –Binary to Hex : Starting from rightmost bit, make groups of 4 bits and convert each group to base = 1000/1100/1110 = 8CE 16 8 / C / E I. Representation of numerical information

Other Conversions From Octal/hex ---> Binary Conversion by substitution – Octal to Binary : Convert each digit to a 3 bits binary number = –Hex to Binary : Convert each digit to a 4 bits binary number = I. Representation of numerical information

Addition of binary numbers Example 1 (Addition) Carry X Y Result has more bits than binary addends Carry equals 1 in the last bit position Example 2 (Addition) Carry X Y Carry equal to 0 in the last bit position I. Representation of numerical information

Addition of binary numbers In general, given two binary number X = ( x n-1 … x i … x 1 x 0 ) 2 and Y = ( y n-1 … y i … y 1 y 0 ) 2 the sum (X+Y) bit by bit at position i is given by (c i is the ith position’s carry) c i-1 Addition table + x i ci-1 xi yi si ci + y i c i s i I. Representation of numerical information

Substraction of binary numbers Substraction B X Y B X Y I. Representation of numerical information

Addition of hexadecimal numbers C 1 1 X 1 9 B Y C 7 E 6 16 E 1 9 F 16 I. Representation of numerical information Addition of two hexadecimal numbers

Representation of negative numbers Signed-magnitude systems +99, -57, Binary uses a (sign bit, the most significant bit (MSB)) MSB = 0 (Positive) MSB = 1 (Negative) = = = = = = Problem: Too much logic needed to - detect and compare sign bit - add or abstract magnitudes - determine the sign of the result I. Representation of numerical information

Representation of negative numbers Complement number system Difficult to change to complement But adding or substracting two numbers are easier once they are represented in complement number systems I. Representation of numerical information

Representation of negative numbers Radix – Complement representation n digit number is substracted from r n Example: if r = 10 and n = 4, r n = 10 4 =10,000 The 10’s complement of D= is: (r n – D) = 8151 Computing 10’s complement: r n – D = (r n - 1 – D) +1 (r n - 1) – D => complement of each digit with rspect to base (r-1) In base 10 complement each digit with respect to 9 and 1 to the result Example: The 10’s complement of is ( )= (9999 – 1849) + 1 = = 8151 I. Representation of numerical information

Representation of negative numbers Radix – Complement representation Complement of each digit : r –1 – d i In base 10 : 10 –1 – d i = 9 – d i Example : The complement of each digit of 345 is : For 5 : (10 – 1) – 5 = 9 – 5 = 4 For 4 : = 9 – 4 = 5 For 3 : = 9 – 3 = 6 In base 3 the radix complement of 121 is 101 In base 2 the radix complement of is I. Representation of numerical information

Representation of negative numbers Two’s Complement The MSB is the sign bit Example: = = = = The range is -(2 n-1 ) -> (2 n-1 -1), For n= = = I. Representation of numerical information Note: The weight of the MSB is –2 n-1 The range of positive numbers is 0 to 127 The range of negative numbers is –1 to -128

Representation of negative numbers Two’s Complement Two’s complement of 0 10 and = = = = I. Representation of numerical information Note: Ignore carry out of the MSB position Note: -128 does not have a positive counterpart, that is –128 is its own Complement : this can creat problems ……

2’s Complement Addition + Substraction > > > > > => = 3 I. Representation of numerical information Overflow in the last position Rule : Ignore any carry beyond the MSB. The result is correct if the range of the number system Is not exceeded.

2’s Complement Addition + Substraction I. Representation of numerical information Addition/Substraction rule : Assume that the signed integers are represented in 2s complement : To compute A – B, compute the 2’s complement B’ of B and add B’ to A Examples : ( = 2’) (ignore the leftmost carry

Overflow Addition of 2 numbers with different signs can never overflow Addition of 2 numbers with same sign = = -5wrong If signs of (addends) are same and sign of sum is different I. Representation of numerical information

Substraction rules (2’s complement) Same overflow rules apply I. Representation of numerical information

Binary multiplication  uses a shift register and adder, and logic control Signed multiplication +  + = + +  - = - -  - = + I. Representation of numerical information

Binary codes for decimal numbers Goal: Use binary strings (sequence of 0’s and 1’s) to represent decimal information Definition: A code is a set of n-bit strings. Each n-bit string represrnts a different number. A code word is a particular member of a code II. Representation of non numerical information

Binary codes for decimal numbers A code is a set of n-bit strings. Each n-bit string represrnts a different number. A code word is a particular member of a code If n bit is used to represent each code words, the total number of possible code words is 2 n Examples: To encode a set consisting of 3 elements {A,B,C} we need 2 bits to represent each code word. The possible code words are {00, 01, 10, 11} II. Representation of non numerical information

Binary codes for decimal numbers We need to assign a code word to each element of the original set. Assignment 1 : > A > B > C Code 11 is unused Another assignment : > A > B > C Code 00 is unused II. Representation of non numerical information

Binary codes for decimal numbers To encode the 10 decimal digits {0,1,….,8,9} We need 4 bit binary code words. There are 16=2 4 possible code words. So 6 codes are unused. Assignment 1 : > > > > > > > > > > 1001 The following codes are unused: 1010, 1011, 1100, 1101, 1110, 1111 II. Representation of non numerical information