Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE20 Lecture 2: Number Systems: Binary Numbers and Gray Code CK Cheng 1.

Similar presentations


Presentation on theme: "CSE20 Lecture 2: Number Systems: Binary Numbers and Gray Code CK Cheng 1."— Presentation transcript:

1 CSE20 Lecture 2: Number Systems: Binary Numbers and Gray Code CK Cheng 1

2 Number Systems 1.Introduction 2.Binary Numbers 3.Gray code 4.Negative Numbers 5.Residual Numbers 2

3 2. Binary Numbers: iClicker What is the extent of a binary number system A. Coverage of integer and floating point numbers B. Mechanism of addition and subtraction operations C. Operations of logic functions D. All of the above E. None of the above. 3

4 2. Binary Numbers 1.Definition (radix 2) 2.Enumerations (value -> index) 3.Addition (logic -> hardware) 4

5 2.1 Definition of Binary Numbers Format: An n digit binary number (b n-1, …, b 1, b 0 ) 2 where b i in {0,1} for 0<= i < n Value: b n-1 2 n-1 + …+b 1 2 1 +b 0 2 0 Non-redundancy: The system is non- redundant, i.e. different binary numbers represent different values. 5

6 2.2 Enumeration of Binary Numbers idb2b1b0b2b1b0 0000 1001 2010 3011 4100 5101 6110 7111 6 idb1b0b1b0 000 101 210 311 idb0b0 00 11 1 digit2 digits3 digits4 digits? idb3b2b1b0b3b2b1b0 00000 10001 20010 30011...... 141110 151111 An n digit binary code covers numbers from 0 to 2 n -1.

7 2.2 Enumeration of binary numbers iCliker When we enumerate binary numbers (b 3 b 2 b 1 b 0 ) 2 from 0 to 15, the sequence of b 3 should be A. 0101010101010101 B. 0011001100110011 C. 0000111100001111 D. 0000000011111111 7

8 2.3 Addition of Binary Numbers Given two binary numbers A & B, we derive binary number S so that the value of S is equal to the sum of the values of A & B, i.e. (a n-1 …,a 1 a 0 ) 2 +(b n-1 …b 1 b 0 ) 2 =(s n-1 …s 1 s 0 ) 2 Caution: Overflow, i.e. the sum is beyond the range of the representation. 8

9 2.3 Addition: iClicker Given two binary numbers A=(a n-1 …,a 1 a 0 ) 2 and B=(b n-1 …b 1 b 0 ) 2 what is the largest possible value of A+B? A.2 n+1 B.2 n+1 -1 C.2 n+1 -2 D.None of the above 9

10 2.3 Addition of Binary Numbers Equality of addition (a n-1 …,a 1 a 0 ) 2 +(b n-1 …b 1 b 0 ) 2 =(s n-1 …s 1 s 0 ) 2 That is to say a n-1 2 n-1 +…+a 1 2 1 +a 0 2 0 +b n-1 2 n-1 +…+b 1 2 1 +b 0 2 0 =(a n-1 +b n-1 )2 n-1 +…+(a 1 +b 1 )2 1 +(a 0 +b 0 )2 0 =s n-1 2 n-1 +…+s 1 2 1 +s 0 2 0 10

11 2.3 Addition of Binary Numbers b2b2 b1b1 b0b0 Value 0000 0011 0102 0113 1004 1015 1106 1117 8421 0011 0101 8421 0011 0110 + + Examples: 11

12 2.3 Addition of Binary Numbers Bit i+1 Bit i Bit i-1 Carry i+1 Carry i aiai a i-1 bibi b i-1 Sum i Sum i-1 12 Formula for Bit i: Carry i +a i +b i = 2xCarry i+1 +Sum i

13 2.3 Adding 2 bits in a digit ab CarrySum 0000 0101 1001 1110 Formula: a+b= 2xCarry + Sum 13

14 2.3 Adding 3 bits in a digit idabc CarrySum 000000 100101 201001 301110 410001 510110 611010 711111 Formula: a+b+c= 2xCarry + Sum 14

15 3. Gray Code 1.Introduction 2.Example 3.Construction 4.Comments 15

16 3.1 Gray Code: Introduction Gray: Frank Gray patented the code in 1947 A variation of binary code The code will be used for logic operation (CSE20, CSE140) Feature: only one bit changes for two consecutive numbers 16

17 3.2 Gray Code: Example 17 idb2b1b0b2b1b0 g2g1g0g2g1g0 0000 1001 2010011 3 010 4100110 5101111 6110101 7111100 idb1b0b1b0 g1g0g1g0 000 101 21011 3 10 2 digits3 digits Note the difference of the first and last rows.

18 3.2 Gray Code 18 idb2b1b0b2b1b0 g2g1g0g2g1g0 0000 1001 2010011 3 010 4100110 5101111 6110101 7111100 3 digits idb3b2b1b0b3b2b1b0 g3g2g1g0g3g2g1g0 00000 10001 200100011 3 0010 401000110 501010111 601100101 701110100 81000? 91001 101010 111011 121100 131101 141110 151111

19 3.2 Gray Code: iClicker 19 A 4-digit Gray code (g 3 g 2 g 1 g 0 ) at id=8 is written as (ref: previous page) A.(0101) B.(0110) C.(1100) D.None of the above

20 3.3 Gray Code: Construction Construction of n-digit Gray code from n-1 digit Gray code Copy the n-1 digit Gray code for the top 2 n-1 rows. Fill 0 at digit g n-1 in the top rows. Reflect and append the n-1 digit code for the bottom 2 n-1 rows. Fill 1 at digit g n-1 in the bottom rows. 20

21 3.4 Gray Code: Comments There are various codes that satisfy the Gray code feature. Gray code saves communication power when the signals are continuous in nature, e.g. addresses, analog signals Gray code facilitates code checking when the signals are supposed to be continuous in value. For arithmetic operations, we need to convert the values. 21


Download ppt "CSE20 Lecture 2: Number Systems: Binary Numbers and Gray Code CK Cheng 1."

Similar presentations


Ads by Google