12
CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Embed Size (px)

Citation preview

Page 1: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

CPS120: Introduction to Computer Science

Computer Math: Converting to Decimal

Page 2: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

9

Decimal is base 10 and has 10 digits: 0,1,2,3,4,5,6,7,8,9

Binary is base 2 and has 2 digits:

0,1For a number to exist in a given number system, the number system must include those digits. For example:The number 284 only exists in base 9 and higher.

Binary

Page 3: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Codes

Given any positive integer base (RADIX) N, there are N different individual symbols that can be used to write numbers in the system. The value of these symbols range from 0 to N-1

All systems we use in computing are positional systems495 = 400 + 90 +5

Page 4: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Number Systems

We use the DECIMAL (10 system

Computers use BINARY (2 or some shorthand for it like OCTAL (8 or HEXADECIMAL (16

Page 5: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Binary Octal Decimal

000 0 0

001 1 1

010 2 2

011 3 3

100 4 4

101 5 5

110 6 6

111 7 7

100 10 8

1001 11 9

1010 12 10 16

Power of 2 Number System

Page 6: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

10

How are digits in bases higher than 10 represented?

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

Bases Higher than 10

Page 7: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Conversions

Decimal Binary Octal Hex0 0000 0 01 0001 1 12 0010 2 23 0011 3 34 0100 4 45 0101 5 56 0110 6 67 0111 7 78 1000 10 89 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E

Page 8: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Decimal Equivalents

Assuming the bits are unsigned, the decimal value represented by the bits of a byte can be calculated as follows:

1. Number the bits beginning on the right using superscripts beginning with 0 and increasing as you move left• Note: 20, by definition is 1

2. Use each superscript as an exponent of a power of 2

3. Multiply the value of each bit by its corresponding power of 2

4. Add the products obtained

Page 9: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

What is the decimal equivalent of the octal number 642?

6 x 8² = 6 x 64 = 384 + 4 x 8¹ = 4 x 8 = 32 + 2 x 8º = 2 x 1 = 2

= 418 in base 10

11

Converting Octal to Decimal

Page 10: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

What is the decimal equivalent of the hexadecimal number DEF?

D x 16² = 13 x 256 = 3328 + E x 16¹ = 14 x 16 = 224 + F x 16º = 15 x 1 = 15

= 3567 in base 10

Remember, base 16 is 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

Converting Hexadecimal to Decimal

Page 11: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

What is the decimal equivalent of the binary number 010110?

1 x 26 = 1 x 64 = 64 + 1 x 25 = 1 x 32 = 32 + 0 x 24 = 0 x 16 = 0 + 1 x 23 = 1 x 8 = 8 + 1 x 22 = 1 x 4 = 4

+ 1 x 21 = 1 x 2 = 2 + 0 x 2º = 0 x 1 = 0

= 112 in base 10

13

Converting Binary to Decimal

Page 12: CPS120: Introduction to Computer Science Computer Math: Converting to Decimal

Horner’s Method

Another procedure to calculate the decimal equivalent of a binary number Note: This method works with any base

Horner’s Method: Step 1: Start with the first digit on the left Step 2: Multiply it by the base Step 3: Add the next digit Step 4: Multiply the sum by the base Step 5: Continue the process until you add the last

digit