1.1 Number Systems

15
Number Systems and Data Representations

Transcript of 1.1 Number Systems

Page 1: 1.1 Number Systems

Number Systems and Data Representations

Page 2: 1.1 Number Systems

Number System

Since the computer is a digital machine, all information given to it must be digitized (binary form)

Common Number Systems

Number System No. of Valid Digits Valid Digits

Base 2 Binary 2 0,1

Base 3 3 0,1,2

Base 4 4 0,1,2,3

Base 8 Octal 8 0,1,2,3,4,5,6,7

Base 10 Decimal 10 0,1,2,3,4,5,6,7,8,9

Base 16 Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

2

Page 3: 1.1 Number Systems

3

Page 4: 1.1 Number Systems

Number System

Using binary format in giving instructions to the computer is tedious and difficult.

Programmers usually use the decimal, octal, or hexadecimal format for clarity.

Number system is just a representation of data; thus a number in one base has its equivalent in another base.

A programmer must be familiar in converting a number

from one base to another.

4

Page 5: 1.1 Number Systems

Decimal Numbers to Other Bases

2010 = 101002 3010 = _______8 4010 = _______16

Solution:Divide with the

destination base Until quotient is Zero

Quotient Read the Remainder Upwards

20/2 10 0

10/2 5 0

5/2 2 1

2/2 1 0

1/2 0 1

5

Page 6: 1.1 Number Systems

Decimal (Base 10) to Other Bases20.687510 = 10100.10112 30.610 =

____________8

Solution:

Step 1: Convert the integral part using the previous step.

Step 2: Convert the fraction part by following the steps below.

Multiply the fraction part with the destination base until it becomes

zero

Take note of the integral part of the result then read downwards

.6875 x 2 1.375

.375 x 2 0.75

.75 x 2 1.5

.5 x 2 1.0

6

Page 7: 1.1 Number Systems

Other Bases to Base 10 (Decimal)

101002 = 2010 368 = ____10

Solution:

Exponent 4 3 2 1 0

Value of 2 raise to the exponent

16 8 4 2 1

Digit 1 0 1 0 0

Multiply the digit with 2x then add the results.

16 0 4 0 0

7

Page 8: 1.1 Number Systems

Other Bases to Base 10 (Decimal)

10100.112 = 20.7510 36.58 = ____10

Solution:Exponents 4 3 2 1 0 -1 -2

Value of 2 raise to the exponent

16 8 4 2 1 0.50.25

Digit 1 0 1 0 0 1 1

Multiply the digit with 2x then add the results. Do it separately for integral and fraction part.

16 0 4 0 0 .5 .25

8

Page 9: 1.1 Number Systems

Shortcut Conversion: Base 10 to Base 2 or Vice Versa

101012 = 2110 3010 = 111102

Solution:Result=Sum (Digit=1 x value)

16 0 4 0 1

Value( 2exponent) 16 8 4 2 1

Exponent 4 3 2 1 0

Binary Digit 1 0 1 0 1

9

Page 10: 1.1 Number Systems

Shortcut Conversion: Base 2 to Base 8 or Vice Versa

Group the bits into 3 Examples:

11 001 1002 = 3148

5628 = _________2

BASE 2 BASE 8

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

10

Page 11: 1.1 Number Systems

Shortcut Conversion:Base 2 to Base 16 or Vice Versa

Group the bits into 4 Examples:

1110 01012 = E516

A4C16 = _________2

BASE 2 BASE 16

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

1000 8

1001 9

1010 A

1011 B

1100 C

1101 D

1110 E

1111 F

11

Page 12: 1.1 Number Systems

Seatwork

64.210 = ______2

______8

______16

101110.1012 = ______8

______10

______16

75.128 = ______2

______10

______16

9D16 = ______2

______8

______10

12

Page 13: 1.1 Number Systems

Arithmetic

Addition

3310

+ 1810

5110

34A516

+ 34A516

694A16

1101012

+ 01012

1110102

1238

+ 78

1328

Subtraction

5110

- 1810

3310

694A16

- 34A516

34A516

1110102

- 01012

1101012

1348

- 78

1258

13

Page 14: 1.1 Number Systems

Arithmetic

Multiplication

10112

x 112

10112

+ 10112

1000012

34A516

x 216

694A16

112

x 112

112

+ 112

10012

1238

+ 58

6378

14

Page 15: 1.1 Number Systems

ArithmeticDivision

10112

112 1000012

112

102

02

1002

112

112

112

02

34A516

216 694A16

616

916

816

1416

1416

A16

A16

016

58 128

15