numbering system base conversion. number systems decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 binary –...

29
Numbering System Base Conversion

Upload: jonas-ross

Post on 02-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Numbering System

Base Conversion

Page 2: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Number systems

Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9Binary – 0, 1Octal – 0, 1, 2, 3, 4, 5, 6, 7Hexadecimal system – 0, 1, 2, 3, 4, 5, 6,

7, 8, 9, A, B, C, D, E, F

Page 3: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Why different number systems?

Binary number result in quite a long string of 0s and 1s

Easier for the computer to interpret input from the user

Page 4: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base Conversion

In daily life, we use decimal (base 10) number system

Computer can only read in 0 and 1Number system being used inside a

computer is binary (base 2)Octal (base 8) and hexadecimal (base 16)

are used in programming for convenience

Page 5: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base Conversion

ConversionBinary number, Octal number, Hexadecimal number, and Decimal number.

Page 6: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base ConversionBinary Octal Hexadecimal Decimal

0000 0 0 0

0001 1 1 1

0010 2 2 2

0011 3 3 3

0100 4 4 4

0101 5 5 5

0110 6 6 6

0111 7 7 7

1000 10 8 8

1001 11 9 9

1010 12 A 10

1011 13 B 11

1100 14 C 12

1101 15 D 13

1110 16 E 14

1111 17 F 15

Page 7: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base Conversion

For example:62 = 111110 = 76 = 3Edecimal binary octal hexadecimal

1 For Decimal: 62 = 6x101 + 2x100

2 For Binary: 111110 = 1x25 + 1x24 + 1x23 + 1x22 + 1x21 + 0x20

3 For Octal: 76 = 7x81+ 6x80

4 For Hexadecimal: 3E = 3x161 + 14x160

Since for hexadecimal system, each digit contains number from 1 to 15, thus we use A, B, C, D, E and F to represent 10, 11, 12, 13, 14 and 15.

Page 8: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Binary and decimal system

Binary to decimal X . 27 + X . 26+ X . 25+ X . 24 + X . 23+ X . 22+ X . 21 +

X . 20

Decimal to binaryKeep dividing the number by two and keep

track of the remainders.Arrange the remainders (0 or 1) from the

least significant (right) to most significant (left) digits

Page 9: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Octal and Hexadecimal system

Binary to Octal (8 = 23) Every 3 binary digit equivalent to one octal digit

Binary to Hexadecimal (16 = 24) Every 4 binary digit equivalent to one hexadecimal

digit Octal to binary

Every one octal digit equivalent to 3 binary digit Hexadecimal to binary

Every one hexadecimal digit equivalent to 4 binary digits

Page 10: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base Conversion

How to convert the decimal number to other number systeme.g. convert 1810 in binary form

2 |18 ----0

2 |09 ----1

2 |04 ----0

2 |02 ----0

1

1810 = 100102

Page 11: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base Conversion

e.g. convert 1810 in octal formSince for octal form, one digit is equal to 3

digits in binary number, we can change binary number to octal number easily.

e.g. 10010 = 010 010

2 2

Thus, 100102 = 228

Page 12: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Base Conversion

e.g. convert 1810 in hexadecimal formSimilarly, for hexadecimal form, one digit is

equal to 4 digits in binary number.e.g. 10010 = 0001 0010

1 2

Thus, 100102 = 1216

Page 13: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Numbering System

Addition & Subtraction

Page 14: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Decimal Addition

111

3758

+ 4657

8415

What is going on?

1 1 1 (carry)

3 7 5 8

+ 4 6 5 7 14 11 15- 10 10 10 (subtract the base)

8 4 1 5

Page 15: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Binary Addition

Rules. 0 + 0 = 00 + 1 = 11 + 0 = 11 + 1 = 2 = 102 = 0 with 1 to carry

1 + 1 + 1 = 3 = 112 = 1 with 1 to carry

Page 16: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Binary Addition

1 1 1 1 1 1 0 1 1 1

+ 0 1 1 1 0 0

2 3 2 2

- 2 2 2 2

1 0 1 0 0 1 1

Verification

5510

+ 2810

8310

64 32 16 8 4 2 1 1 0 1 0 0 1 1

= 64 + 16 + 2 +1

= 8310

Page 17: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Binary Addition

ex Verification 1 0 0 1 1 1 + 0 1 0 1 1 0 + ___ ___________ 128 64 32 16 8 4 2 1

= =

Page 18: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Octal Addition

1 1

6 4 3 78 + 2 5 1 08 9 9 - 8 8 (subtract Base (8)) 1 1 1 4 78

Page 19: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Octal Addition

ex

3 5 3 68 + 2 4 5 78

- (subtract Base (8))

Page 20: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Hexadecimal Addition

1 1

7 C 3 916 + 3 7 F 216 20 18 11 - 16 16 (subtract Base (16))

B 4 2 B16

Page 21: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Hexadecimal Addition

8 A D 416

+ 5 D 616 - (subtract Base (16))

16

Page 22: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Decimal Subtraction

7 13 10

8 4 1 15

- 4 6 5 7

3 7 5 8

How it was done?( add the base 10 when borrowing)

10 10 7 3 0 10

8 4 1 5 13 10 15

- 4 6 5 7

3 7 5 8

Page 23: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Binary Subtraction

1 2 1

0 2 0 2 2 1 0 1 0 0 1 1 - 0 1 1 1 0 0 1 1 0 1 1 1

Verification

8310

- 2810

5510

64 32 16 8 4 2 1

1 1 0 1 1 1

= 32 + 16 + + 4 + 2 +1

= 5510

Page 24: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Binary Subtraction

ex Verification 1 0 0 1 1 1 - 0 1 0 1 1 0 - ___ ___________ 128 64 32 16 8 4 2 1

= =

Page 25: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Octal Subtraction

8 0 0 8

1 1 1 4 78

8 9

- 6 4 3 78

2 5 1 08

Page 26: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Octal Subtraction

ex

3 5 3 68

- 2 4 5 78

Page 27: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Hexadecimal Subtraction

B 16

7 C 3 916 19

- 3 7 F 216

4 4 4 716

Page 28: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Hexadecimal Subtraction

8 A D 416

- 5 D 616

16

Page 29: Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system

Let’s do some exercises!

Octal, Hexadecimal, Binary

Addition & Subtraction