1.02 - Understand Numbering Systems - PowerPoint

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Objective 1.

02
Understand Numbering Systems

COMPUTER PROGRAMMING I
Number Systems
2

Number systems we will talk about:

 Decimal (Base10)

 Binary (Base2)

 Hexadecimal (Base16)

Computer Programming I 05/22/2024


Decimal
3

The number system we use in math and in life.

1 2 3 6 7
Base 10: ten one digit numbers: 8
0 9
 0,1,2,3,4,5,6,7,8,9 4 5

 After 9 comes 10
(the first two digit number) of course.

 102= 100
 Base squared = 100

Computer Programming I 05/22/2024


Decimal
4
What can we say about the decimal system? It is our day to day number
system…
The Decimal system has 10 digits; values are from 0 to 9.
0 10 20 30 40 50 60 70 80 90 100
1 11 21 31 41 51 61 71 81 91 101
2 12 22 32 42 52 62 72 82 92 102
3 13 23 33 43 53 63 73 83 93 103
4 14 24 34 44 54 64 74 84 94 104
5 15 25 35 45 55 65 75 85 95 105
6 16 26 36 46 56 66 76 86 96 106
7 17 27 37 47 57 67 77 87 97 107
8 18 28 38 48 58 68 78 88 98 108
9 19 29 39 49 59 69 79 89 99 109
Binary
5

Binary is Base 2

2 one digit numbers


 0 and 1

For example: Base 10 of 4 = Binary 0100 or 100


102=100 – works in binary too! 2 squared = 4

Computer Programming I 05/22/2024


Machine Language
6
Binary or Base2: Only contains 2 types of digits; 1 or 0.
The power of 2. Each digit from the right to the left is increased
by power of 2.
Each one (1) digit has a value representing on and each zero (0)
digit do not hold a value representing off.

OOOO OOOO
128 64 32 16 8 4 2 1

Ex: 0000 1001= The right most digit (1) = 1 (20)


The two middle digits are 0 therefore have no value.
The left most digit (1) = 8 (23 or 2x2x2). The other digits have
no value. The total value of all numbers would = 9. (8+0+0+1)
ex: 0000 1111 8+4+2+1 = 15 in decimal amount
1111 1111 128+64+32+16+8+4+2+1 = 255
Why Binary?
7

Computers operate on a series on electric impulses.

If the current is flowing the circuit is complete (1),


otherwise the current is off (0)

Write down the powers of 2 from 0-128.

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

Computer Programming I 05/22/2024


Powers of 2
8

Remember from math the powers of 2:

1, 2, 4, 8, 16, 32, 64, 128 (first 8)

Remember any number to the zero power is 1 and


any number to the 1 power is that number.

So if Decimal 4= 100 in binary, what does decimal 5


equal in binary?

Computer Programming I 05/22/2024


Powers of 2
9

Remember from math the powers of 2:

1, 2, 4, 8, 16, 32, 64, 128 (first 8)

Remember any number to the zero power is 1 and


any number of the 1 power is that number.

So if Decimal 4= 1001 in0binary,


1 what does decimal 5
equal in binary? 22 21 20
 A: 101 4 2 1

Computer Programming I 05/22/2024


The 1’s
10

So let’s go beyond our basic example.


Remember the most right digit has the least
significant value and the most left digit has the most
significant value.
What is 1111 1111 in Decimal?

That would be 255. So… 1 0000 0000 would be 256,


right? 1 1 1 1 1 1 1 1
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 0 0 0 0 0 0 0
28 27 26 25 24 23 22 21 20
Computer Programming I 256 128 64 32 16 8 4 2 1 05/22/2024
Let’s Try This…
11

On your paper draw 8 columns

Above each column label a power of 2, starting at 128


in the first (left most) column. Finish with 1 in the
last (right most) column.

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

Computer Programming I 05/22/2024


Example Binary
12

Figure out the following numbers in binary…


Decimal
56
100
198
27 26 25 24 23 22 21 20
64 128 64 32 16 8 4 2 1

18
84
231

Computer Programming I 05/22/2024


Example Binary Answers
13

Figure out the following numbers in binary:


Dec Binary (Answer)
56  111000
100 1100100
198 1100110
64  1000000
18  10010
84  1010100
231 11100111

Computer Programming I 05/22/2024


Hexadecimal
14

Hex is Base 16

There are sixteen one digit numbers:


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

What comes after F?

Remember our rule: 102=100 (162=256 in decimal)


 This works in Hex as it does for ANY number system.

Computer Programming I 05/22/2024


Hexadecimal
15
Contains 16 digits starting with 0-9 & A-F containing the values from 0 – 15.
Hex Dec Hex Dec -Hex 20-2F and so on…
0 = 0 10 = 16 -Each digit carries a value of 16.
1 = 1 11 = 17 -Hex = 6 + Decimal = 10 (Hexadecimal
=16)
2 = 2 12 = 18 -Hexadecimal is only 4 bits (binary value)
3 = 3 13 = 19 -ex: 1111 = 15 in decimal “F” in Hex value
4 = 4 14 = 20 -Another ex: 1001 1100 = 9C in Hex and
5 = 5 15 = 21 -156 in Decimal value.
6 = 6 16 = 22
7 = 7 17 = 23
8 = 8 18 = 24
9 = 9 19 = 25 Remember! Hex is only 4 bits long and its
A = 10 1A = 26 highest value is F in Hex or
B = 11 1B = 27 15 in decimal or 1111 in binary.
C = 12 1C = 28
D = 13 1D = 29 Mainframe computers use Hexadecimal to
E = 14 1E = 30 utilize less disk space.
F = 15 1F = 31
Hexadecimal Conversion
16

Hex 9F to binary
9 F
1 0 0 1 1 1 1 1 9F Base 16 =
23
8
22
4
21
2
20
1
23
8
22
4
21
2
20
1
1001 1111 Base 2

Hex 9F to Decimal
9 F 9F Base 16 =
161 160 159 Base 10
16 16
(16 * 9) + (1 * 15) = 159 in Decimal Add the values…

Computer Programming I
Hexadecimal
17

Think if you had 3 hands. You would have 15 fingers


right?
That is what hex has!

So after 9 comes A (10), B (11), C (12), D (13), E (14)


and F (15)
Let try our example again in Hex.

Computer Programming I 05/22/2024


Another Conversion to Hexadecimal
18

Figure out the following Decimal numbers to Hex:


Decimal
3 8
56
162 161 160
100 256 16 1
198
1. Ask “How many of ‘256’ can come out of 56 (our
64 decimal number)?
0
18 2. Ask “How many of ‘16’ can come out of 56?
3 (3 * 16 = 48 with 8 left over)
128 Put the 3 in the 16’s spot
231 3. Ask “How many of ‘1’ can come out of 8 (the left
over)?
8 with 0 left over

Computer Programming I 05/22/2024


Example Hex Answers
19

Figure out the following Decimal numbers to Hex:


Dec Hex
56  38
100 64
198 C6
64  40
18  12
128 80
256 100

Computer Programming I 05/22/2024


Conclusion
20

In this lesson we learned about number systems


used in Programming.

Decimal
Binary
Hexadecimal

Computer Programming I 05/22/2024


For More Information
24

http://software2i.com/viewthread.php?tid=56509&
extra=page%253D1&page=1

http://www.tpub.com/neets/book13/53e.htm

http://www.plcs.net/chapters/number23.htm

You might also like