Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.

Similar presentations


Presentation on theme: "ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech."— Presentation transcript:

1 ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech

2 2 2 Decimal Number Representation Example: 90134 (base-10, used by Homo Sapien) = 90000 + 0 + 100 + 30 + 4 = 9*10 4 + 0*10 3 + 1*10 2 + 3*10 1 + 4*10 0 How did we get it?90134 10 9013 4 901 901103 90 90101 90

3 3 3 Generic Number Representation 90134 = 9*10 4 + 0*10 3 + 1*10 2 + 3*10 1 + 4*10 0 A 4 A 3 A 2 A 1 A 0 for base-10 (or radix-10) = A 4 *10 4 + A 3 *10 3 + A 2 *10 2 + A 1 *10 1 + A 0 *10 0 (A is coefficient; b is base) N bGeneralize for a given number N w/ base-b N N = A n-1 A n-2 … A 1 A 0 N N = A n-1 *b n-1 + A n-2 *b n-2 + … + A 2 *b 2 + A 0 *b 0 **Note that A < b

4 4 4 b Counting numbers with base-b 012345678910111213141516171819 Base-1090919293949596979899 ….. 100101102103104105106107108109 How about Base-8 01234567101112131415161720212223242526277071727374757677 ….. 100101102103104105106107 20212223242526272829

5 5 5 2 How about base-2 011011 10010111011110001001101010111100110111101111

6 6 6 01101110010111011110001001101010111100110111101111

7 7 7 0 = 0 1 = 1 10 = 2 11 = 3 100 = 4 101 = 5 110 = 6 111 = 7 1000 = 8 1001 = 9 1010 = 10 1011 = 11 1100 = 12 1101 = 13 1110 = 14 1111 = 15 Binary = Decimal

8 8 8 Derive Numbers in Base-2 Decimal (base-10) –(25) 10 Binary (base-2) –(11001) 2 Exercise252 12 21 6 20 3 20 11

9 9 9 Base-2 Decimal (base-10) –(982) 10 Binary (base-2) –(1111010110) 2 Exercise

10 10 Base 8 Decimal (base-10) –(982) 10 Octal (base-8) –(1726) 8 Exercise

11 11 Base 16 Decimal (base-10) –(982) 10 Hexadecimal (base-16) Hey, what do we do when we count to 10?? 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 150123456789abcdef

12 12 Base 16 (982) 10 = (3d6) 16 (3d6) 16 can be written as (0011 1101 0110) 2 We use Base-16 (or Hex) a lot in computer world 0xfe8a7d20 ( 0x ) –Ex: A 32-bit address can be written as 0xfe8a7d20 ( 0x is an abbreviation of Hex) –Or in binary form 1111_1110_1000_1010_0111_1101_0010_0000

13 13 Number Examples with Different Bases Decimal (base-10) –(982) 10 Binary (base-2) –(01111010110) 2 Octal (base-8) –(1726) 8 Hexadecimal (base-16) –(3d6) 16 Others examples: –base-9 = (1321) 9 –base-11 = (813) 11 –base-17 = (36d) 17

14 14 Convert between different bases Convert a number base-x to base-y, e.g. (0100111) 2 to (?) 6 –First, convert from base-x to base-10 if x  10 –Then convert from base-10 to base-y 0100111 = 0  2 6 + 1  2 5 + 0  2 4 + 0  2 3 + 1  2 2 + 1  2 1 + 1  2 0 = 393966 6 3 10  (0100111) 2 = (103) 6

15 Base-b Addition

16 16 Negative Number Representation Options –Sign-magnitude –One’s Complement –Two’s Complement (we use this in this course)

17 17 Sign-magnitude Use the most significant bit (MSB) to indicate the sign –01 –0: positive, 1: negative Problem –Representing zeros? –Do not work in computation We will NOT use it in this course ! +0000 +1001 +2010 +3011 -3111 -2110 101 0100

18 18 One ’ s Complement Complement (flip) each bit in a binary number Problem –Representing zeros? –Do not always work in computation Ex: 111 + 001 = 000  Incorrect ! We will NOT use it in this course ! +0000 +1001 +2010 +3011 -3100 -2101 110 0111

19 19 Two ’ s Complement Complement adding 1Complement (flip) each bit in a binary number and adding 1, with overflow ignored Work in computation perfectly We will use it in this course ! 011 100 One’s complement 3 101 Add 1 -3 010 One’s complement 101-3 011 Add 1 3

20 20 Two ’ s Complement Complement adding 1Complement (flip) each bit in a binary number and adding 1, with overflow ignored Work in computation perfectly We will use it in this course ! 0000 +1001 111 +2010 -2110 +3011 -3101 ??100 011 One’s complement 100 Add 1 The same 100 represents both 4 and -4 which is no good

21 21 Two ’ s Complement Complement adding 1Complement (flip) each bit in a binary number and adding 1, with overflow ignored Work in computation perfectly We will use it in this course ! 0000 +1001 -1 1 111 +2010 -2-2 1 110 +3011 -3-3 1 101 --4--4 1 100 100 011 One’s complement 100 Add 1 MSB = 1 for negative Number, thus 100 represents -4

22 22 Range of Numbers An N-bit number –Unsigned: 0.. (2 N -1) –Signed: -2 N-1.. (2 N-1 -1) Example: 4-bit 1110 (-8) 0111 (7) Signed numbers 0000 (0) 1111 (15) Unsigned numbers

23 23 Binary Computation 010001 (17=16+1) 001011 (11=8+2+1) --------------- 011100 (28=16+8+4) Unsigned arithmetic 010001 (17=16+1) 101011 (43=32+8+2+1) --------------- 111100 (60=32+16+8+4) Signed arithmetic (w/ 2’s complement) 010001 (17=16+1) 101011 (-21: 2’s complement=010101=21) --------------- 111100 (2’s complement=000100=4, i.e. -4)

24 24 Binary Computation Unsigned arithmetic 101111 (47) 011111 (31) --------------- 001110 (78?? Due to overflow, note that 62 cannot be represented by a 6-bit unsigned number) The carry is discarded Signed arithmetic (w/ 2’s complement) 101111 (-17 since 2’s complement=010001) 011111 (31) --------------- 001110 (14) The carry is discarded

25 BACKUP

26 26 Application of Two ’ s Complement Pocket Calculator subtractionThe first Pocket Calculator “ Curta ” used Two ’ s complement method for subtraction First complement the subtrahend –Fill the left digits to be the same length of the minuend –Complemented number = (9 – digit) 4 ’ s complement = 5 7 ’ s complement = 2 0 ’ s complement = 9 Add 1 to the complemented number Perform an addition with the minuend

27 27 Examples 13 – 7 –Two’s complement of 07 = 92 + 1 = 93 –13 + 93 = 06 (ignore the leftmost carry digit) 817 – 123 –Two’s complement of 123 = 876 + 1 = 877 –817 + 877 = 694 (ignore the leftmost carry digit) 78291 – 4982 – Two’s complement of 04982 = 95017 + 1 = 95018 –78291 + 95018 = 73309 (ignore the leftmost carry digit)


Download ppt "ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech."

Similar presentations


Ads by Google