ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech
2 2 Decimal Number Representation Example: (base-10, used by Homo Sapien) = = 9* * * * *10 0 How did we get it?
3 3 Generic Number Representation = 9* * * * *10 0 A 4 A 3 A 2 A 1 A 0 for base-10 (or radix-10) = A 4 * A 3 * A 2 * A 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 b Counting numbers with base-b Base … How about Base …
5 5 2 How about base
7 7 0 = 0 1 = 1 10 = 2 11 = = = = = = = = = = = = = 15 Binary = Decimal
8 8 Derive Numbers in Base-2 Decimal (base-10) –(25) 10 Binary (base-2) –(11001) 2 Exercise
9 9 Base-2 Decimal (base-10) –(982) 10 Binary (base-2) –( ) 2 Exercise
10 Base 8 Decimal (base-10) –(982) 10 Octal (base-8) –(1726) 8 Exercise
11 Base 16 Decimal (base-10) –(982) 10 Hexadecimal (base-16) Hey, what do we do when we count to 10?? abcdef
12 Base 16 (982) 10 = (3d6) 16 (3d6) 16 can be written as ( ) 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 Number Examples with Different Bases Decimal (base-10) –(982) 10 Binary (base-2) –( ) 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 Convert between different bases Convert a number base-x to base-y, e.g. ( ) 2 to (?) 6 –First, convert from base-x to base-10 if x 10 –Then convert from base-10 to base-y = 0 2 0 = ( ) 2 = (103) 6
Base-b Addition
16 Negative Number Representation Options –Sign-magnitude –One’s Complement –Two’s Complement (we use this in this course)
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 !
18 One ’ s Complement Complement (flip) each bit in a binary number Problem –Representing zeros? –Do not always work in computation Ex: = 000 Incorrect ! We will NOT use it in this course !
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 ! One’s complement Add One’s complement Add 1 3
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 ! ?? One’s complement 100 Add 1 The same 100 represents both 4 and -4 which is no good
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 ! One’s complement 100 Add 1 MSB = 1 for negative Number, thus 100 represents -4
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 Binary Computation (17=16+1) (11=8+2+1) (28=16+8+4) Unsigned arithmetic (17=16+1) (43= ) (60= ) Signed arithmetic (w/ 2’s complement) (17=16+1) (-21: 2’s complement=010101=21) (2’s complement=000100=4, i.e. -4)
24 Binary Computation Unsigned arithmetic (47) (31) (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) (-17 since 2’s complement=010001) (31) (14) The carry is discarded
BACKUP
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 Examples 13 – 7 –Two’s complement of 07 = = 93 – = 06 (ignore the leftmost carry digit) 817 – 123 –Two’s complement of 123 = = 877 – = 694 (ignore the leftmost carry digit) – 4982 – Two’s complement of = = – = (ignore the leftmost carry digit)