positional number systems m260 1.5. decimal review 5049 = 5(1000) + 0(100) + 4(10) + 9(1) 5049 =...

29
Positional Number Systems M260 1.5

Upload: gerald-eustace-parks

Post on 02-Jan-2016

221 views

Category:

Documents


2 download

TRANSCRIPT

Positional Number Systems

M260 1.5

Decimal Review

• 5049 = 5(1000) + 0(100) + 4(10) + 9(1)• 5049 = 5·103 + 0·102 + 4·101 + 9·100

place 103 102 101 100

digit 5 0 4 9

Binary Representation

• 27 = 16 + 8 + 2 + 1• 27 = 1·24 + 1·23 + 0·22 + 1·21 + 1·20

• 27 = 110112

place 24 23 22 21 20

digit 1 1 0 1 1

Some Binary Representations010 ?2

110 ?2

210 ?2

310 ?2

410 ?2

510 ?2

610 ?2

710 ?2

810 ?2

910 ?2

Some Binary Representations010 02

110 12

210 102

310 112

410 1002

510 1012

610 1102

710 1112

810 10002

910 10012

Powers of Two

210 29 28 27 26 25 24 23 22 21 20

1024 512 256 128 64 32 16 8 4 2 1

Convert Binary to Decimal

210 29 28 27 26 25 24 23 22 21 20

1024 512 256 128 64 32 16 8 4 2 1

1 1 0 1 0 12

Convert Binary to Decimal

210 29 28 27 26 25 24 23 22 21 20

1024 512 256 128 64 32 16 8 4 2 1

0 0 0 0 0 1 1 0 1 0 1

1 1 0 1 0 12

32 + 16 + 4 + 1 = 53

Convert Decimal to Binary

• 20910 = 128 + smaller number

• = 1(128) + 81

• = 1(128) + 64 + smaller number

• = 1(128) + 1(64) + 17

• = 1(128) + 1(64) + 0(32) + 1(16) + 11(128)+1(64)+0(32)+1(16)+0(8)+0(4)+0(2)+1(1)

= 1 1 0 1 0 0 0 12

Binary Addition

• • 1 1 0 1

+ 1 1 1

12

+ 12

1 02

12

12

+ 12

1 12

Binary Addition

• 1 carry• 1 1 0 1

+ 1 1 1 0

12

+ 12

1 02

12

12

+ 12

1 12

Binary Addition

• 1 1 carry• 1 1 0 1

+ 1 1 1 0 0

12

+ 12

1 02

12

12

+ 12

1 12

Binary Addition

• 1 1 1 carry• 1 1 0 1

+ 1 1 1 1 0 0

12

+ 12

1 02

12

12

+ 12

1 12

Binary Addition

• 1 1 1 carry• 1 1 0 1

+ 1 1 11 0 1 0 0

12

+ 12

1 02

12

12

+ 12

1 12

Subtraction in Decimal System

•1 0 0 010

- 5 810

Subtraction in Decimal System

• 9 9 10 borrowing1 0 0 010

- 5 810

Subtraction in Decimal System

• 9 9 10 borrowing1 0 0 010

- 5 810

9 4 2

Subtraction in Binary System

•1 1 0 0 0 - 1 0 1 1

Subtraction in Binary System

• 0 1 1 10 borrowing1 1 0 0 0 - 1 0 1 1

Subtraction in Binary System

• 0 1 1 10 borrowing1 1 0 0 0 - 1 0 1 1 1 1 0 1

Two’s Complement Arithmetic

• Computers often use 2’s complement arithmetic for working with signed numbers

• 2’s complement of a in n-bit arithmetic is the binary representation of 2n – a

Two’s Complement Example

• The 8 bit representation of -27 is

• ( 28 – 27)10 = 22910

= 1 1 1 0 0 1 0 12

• Or flip the bits and add one

• -27 = -000110112

• = 11100100 + 1

• = 11100101

Two’s Complement Arithmetic

• To subtract, take the two’s complement and then add.

• Otherwise just add the binary numbers and throw away any positions greater than 2n-1.

• If -2n-1 result < 2n-1 then everything is fine.

• Otherwise you have an overflow.

Hexadecimal RepresentationsDecimal Hexadecimal Binary

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Hexadecimal RepresentationsDecimal Hexadecimal Binary

0 0

1 1

2 2

3 3

4 4

5 5

6 6

7 7

8 8

9 9

10 A

11 B

12 C

13 D

14 E

15 F

Hexadecimal RepresentationsDecimal Hexadecimal Binary

0 0 0000

1 1 0001

2 2 0010

3 3 0011

4 4 0100

5 5 0101

6 6 0110

7 7 0111

8 8 1000

9 9 1001

10 A 1010

11 B 1011

12 C 1100

13 D 1101

14 E 1110

15 F 1111

Convert Hexadecimal to Decimal

• 3CF16

• = 3(162) + 12(161) + 15(160)

• = 97510

Convert Hexadecimal to Binary

• C50A16

• C 5 0 A

• 1100 0101 0000 1010

Convert Binary to Hexadecimal

• 0100 1101 1010 1001

• 4 D A 9