Top Banner
Decimal (Base 10) Numbers Positional system - each digit position has a value 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 Alternate view: Digit position I from the right = Digit * 10 I (rightmost is position 0) 2534 = 2*10 3 + 5*10 2 + 3*10 1 + 4*10 0
33

69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

Jan 18, 2016

Download

Documents

Moris Lindsey
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

1

Decimal (Base 10) Numbers

Positional system - each digit position has a value 2534 = 2*1,000 + 5*100 + 3*10 + 4*1

Alternate view: Digit position I from the right = Digit * 10I (rightmost is position 0) 2534 = 2*103 + 5*102 + 3*101 + 4*100

Page 2: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

2

Base R Numbers

Each digit in range 0..(R-1) 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F ...

A = 10 B = 11 C = 12 D = 13 E = 14 F = 15

Digit position I = Digit * RI

D3 D2 D1 D0 (base R) = D3*R3+D2*R2+D1*R1+D0*R0

Page 3: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

3

Number System (Conversion to Decimal)

Binary: (101110)2 =

Octal: (7325)8 =

Hexadecimal: (AFE32)16 =

Page 4: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

4

Conversion from Base R to Decimal

Binary: (110101)2

Octal: (6524)8

Hexadecimal: (94a6)16

Page 5: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

5

Conversion of Decimal to Binary (Method 1)

For positive, unsigned numbers Successively subtract the greatest power of two

less than the number from the value. Put a 1 in the corresponding digit position

20=1 24=16 28=256 212=4096 (4K)

21=2 25=32 29=512 213 =8192 (8K)

22=4 26=64 210=1024 (1K)

23=8 27=128 211=2048 (2K)

Page 6: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

6

Decimal to Binary Method 1

Convert (2578)10 to binary

Convert (289)10 to binary

Page 7: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

7

Conversion of Decimal to Binary (Method 2)

For positive, unsigned numbers Repeatedly divide number by 2. Remainder

becomes the binary digits (right to left) Explanation:

Page 8: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

8

Decimal to Binary Method 2

Convert (289)10 to binary

Page 9: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

9

Decimal to Binary Method 2

Convert (85)10 to binary

Page 10: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

10

Converting Binary to Hexadecimal

1 hex digit = 4 binary digits Convert (11100011010111010011)2 to hex

Convert (A3FF2A)16 to binary

Page 11: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

11

Converting Binary to Octal

1 octal digit = 3 binary digits Convert (10100101001101010011)2 to octal

Convert (723642)8 to binary

Page 12: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

12

Converting Decimal to Octal/Hex

Convert to binary, then to other base Convert (198)10 to Hexadecimal

Convert (1983020)10 to Octal

Page 13: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

13

Arithmetic Operations

5 7 8 9 2+ 7 8 9 5 6

Decimal:

1 0 1 0 1 1 1+ 0 1 0 0 1 0 1

Binary:

5 7 8 9 2- 3 2 9 4 6

Decimal:

1 0 1 0 0 1 1 0- 0 0 1 1 0 1 1 1

Binary:

Page 14: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

14

Arithmetic Operations (cont.)

1 0 0 1* 1 0 1 1

Binary:

Page 15: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

15

Negative Numbers

Need an efficient way to represent negative numbers in binary Both positive & negative numbers will be strings of bits Use fixed-width formats (4-bit, 16-bit, etc.)

Must provide efficient mathematical operations Addition & subtraction with potentially mixed signs Negation (multiply by -1)

Page 16: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

16

Sign/Magnitude Representation

0000

0111

0011

1011

11111110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0+1

+2

+3

+4

+5

+6

+7-0

-1

-2

-3

-4

-5

-6

-7

0 100 = + 4 1 100 = - 4

+

-

High order bit is sign: 0 = positive (or zero), 1 = negative

Three low order bits is the magnitude: 0 (000) thru 7 (111)

Number range for n bits = +/-2 -1

Representations for 0:

n-1

Page 17: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

17

Sign/Magnitude Addition

1 0 1 0 ( -2)+ 0 1 0 0 (+4)

0 0 1 0 (+2)+ 0 1 0 0 (+4)

1 0 1 0 (-2)+ 1 1 0 0 (-4)

0 0 1 0 (+2)+ 1 1 0 0 ( -4)

Bottom line: Basic mathematics are too complex in Sign/Magnitude

Idea: Pick negatives so that addition/subtraction works

Page 18: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

18

Idea: Pick negatives so that addition works

Let -1 = 0 - (+1):

Does addition work?

Result: Two’s Complement Numbers

0 0 0 0 ( 0)- 0 0 0 1 (+1)

0 0 1 0 (+2)+ 1 1 1 1 ( -1)

Page 19: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

19

Two’s Complement

Only one representation for 0 One more negative number than positive number Fixed width format for both pos. & neg. numbers

0000

0111

0011

1011

11111110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

0 011 = + 3

1 101 = - 3

+

-

Page 20: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

20

Negating in Two’s Complement

Flip bits & Add 1 Negate (0010)2 (+2)

Negate (1110)2 (-2)

0000

0111

0011

1011

11111110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

Page 21: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

21

Addition in Two’s Complement

1 1 1 0 ( -2)+ 0 1 0 0 (+4)

0 0 1 0 (+2)+ 0 1 0 0 (+4)

1 1 1 0 (-2)+ 1 1 0 0 (-4)

0 0 1 0 (+2)+ 1 1 0 0 ( -4)

Page 22: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

22

Subtraction in Two’s Complement

A - B = A + (-B) = A + B + 1

0010 - 0110

1011 - 1001

1011 - 0001

Page 23: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

23

Overflows in Two’s ComplementAdd two positive numbers to get a negative number

or two negative numbers to get a positive number

5 + 3 = -9 -7 - 2 = +7

0000

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110

1111

+0

+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

0000

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110

1111

+0

+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

Page 24: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

24

Overflow Detection in Two’s Complement

5

3

-8

0 1 0 1

0 0 1 1

-7

-2

7

1 0 0 1

1 1 1 0

5

2

7

0 1 0 1

0 0 1 0

-3

-5

-8

1 1 0 1

1 0 1 1

Overflow Overflow

No overflow No overflow

Overflow when carry in to sign does not equal carry out

Page 25: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

25

Converting Decimal to Two’s Complement

Convert absolute value to binary, then negate if necessary

Convert (-9)10 to 6-bit Two’s Complement

Convert (9)10 to 6-bit Two’s Complement

Page 26: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

26

Converting Two’s Complement to Decimal

If Positive, convert as normal;If Negative, negate then convert.

Convert (11010)2 to Decimal

Convert (01011) 2 to Decimal

Page 27: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

27

Sign Extension

To convert from N-bit to M-bit Two’s Complement (N>M), simply duplicate sign bit:

Convert (1011)2 to 8-bit Two’s Complement

Convert (0010)2 to 8-bit Two’s Complement

Page 28: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

28

Sign Extension

To convert from N-bit to M-bit Two’s Complement (N>M), simply duplicate sign bit:

Convert (1011)2 to 8-bit Two’s Complement

Convert (0010)2 to 8-bit Two’s Complement

Page 29: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

29

Half AdderWith twos complement numbers, addition is sufficient

Ai 0 0 1 1

Bi 0 1 0 1

Sum 0 1 1 0

Carry 0 0 0 1

AiBi

0 1

0

1

0 1

1 0

Sum = Ai Bi + Ai Bi

= Ai + Bi

AiBi

0 1

0

1

0 0

10

Carry = Ai Bi

Half-adder Schematic

Carry

Sum A i

B i

Page 30: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

30

Full Adder

A

0

0

0

0

1

1

1

1

B

0

0

1

1

0

0

1

1

CI

0

1

0

1

0

1

0

1

S

0

1

1

0

1

0

0

1

CO

0

0

0

1

0

1

1

1

Page 31: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

31

Full Adder/Half Adder

Alternative Implementation: 5 Gates

Half Adder

A

B

Half Adder

A + B

CI

A + B + CIS S

COCOCI (A + B)A B

S

CO

A B + CI (A xor B) = A B + B CI + A CI

Standard Approach: 6 Gates

+

A

AA

B

BB CI

CIS CO

Page 32: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

32

Multi-Bit Addition

+

A3 B3

S3

+

A2 B2

S2

+

A1 B1

S1

+

A0 B0

S0C1C2C3

Cascaded Multi-bit Adder

usually interested in adding more than two bits

this motivates the need for the full adder

Page 33: 69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1,000 + 5*100 + 3*10 + 4*1 n Alternate view: Digit position.

33

Adder/Subtractor

A - B = A + (-B) = A + B + 1

A B

CO

S

+ CI

A B

CO

S

+ CI

A B

CO

S

+ CI

A B

CO

S

+ CI

A3 B3 A2 B2 A1 B1 A0 B0

S3 S2 S1 S0

Overflow