Number Systems

Download Report

Transcript Number Systems

UMBC CMSC 104 – Section 01, Fall 2016
1

Nothing. Enjoy your weekend!
UMBC CMSC 104, Section 01 - Fall 2016
2

I want to try something different with this
class…
 Everyone log off your PC and put away your





phones/calculators/electronic devices!
Break out some paper and a pen/pencil
We will be done the slides quickly.
I will put up some conversion “problems” at the end to
test your understanding.
We’re all adults here – if you need more help, you can
stay. If it “clicks”, you can go.
Don’t be concerned if it doesn’t “click” right away.
Stick around.
UMBC CMSC 104, Section 01 - Fall 2016
3






A bit is a single binary digit (a 1 or 0).
A byte is 8 bits
A word is 32 bits or 4 bytes
Long word = 8 bytes = 64 bits
Quad word = 16 bytes = 128 bits
Programming languages use these
standard number of bits when organizing
data storage and access.
UMBC CMSC 104, Section 01 - Fall 2016
4



The on and off states of the capacitors in
RAM can be thought of as the values 1 and
0, respectively.
Therefore, thinking about how information
is stored in RAM requires knowledge of the
binary (base 2) number system.
Let’s review the decimal (base 10) number
system first.
UMBC CMSC 104, Section 01 - Fall 2016
5
• The decimal number system is a positional
number system.
• Example:
5 6 2 1.4
103 102 101 100
UMBC CMSC 104, Section 01 - Fall 2016
10-1
4 X 10-1
1 X 100
2 X 101
6 X 102
5 X 103
=
.4
=
1
=
20
= 600
= 5000
6


The decimal number system is also known as
base 10. The values of the positions are
calculated by taking 10 to some power.
Why is the base 10 for decimal numbers?
 Because we use 10 digits, the digits 0 through 9.
UMBC CMSC 104, Section 01 - Fall 2016
7


The binary number system is also known as
base 2. The values of the positions are
calculated by taking 2 to some power.
Why is the base 2 for binary numbers?
 Because we use 2 digits, the digits 0 and 1.
UMBC CMSC 104, Section 01 - Fall 2016
8
• The binary number system is also a
positional numbering system.
• Instead of using ten digits, 0 - 9, the
binary system uses only two digits, 0
and 1.
• Example of a binary number and the
values of the positions:
1 0 0 1 1 0 1
26 25 24 23 22 21 20
?
UMBC CMSC 104, Section 01 - Fall 2016
9
1 0 0 1 1 0 1
26 25 24 23 22 21 20
20 = 1
21 = 2
22 = 4
23 = 8
UMBC CMSC 104, Section 01 - Fall 2016
24 = 16
25 = 32
26 = 64
1 X 20 = 1
0 X 21 = 0
1 X 22 = 4
1 X 23 = 8
0 X 24 = 0
0 X 25 = 0
1 X 26 = 64
7710
10
Practice conversions:
Binary
Decimal
11101
1010101
100111
?
UMBC CMSC 104, Section 01 - Fall 2016
11
• Make a list of the binary place values up to the number
being converted.
• Perform successive divisions by 2, placing the remainder
of 0 or 1 in each of the positions from right to left.
• Continue until the quotient is zero.
• Example: 4210
25 24 23 22 21 20
32 16 8 4 2 1
1
0 1 0 1 0
UMBC CMSC 104, Section 01 - Fall 2016
12
Practice conversions:
Decimal
Binary
59
82
175
UMBC CMSC 104, Section 01 - Fall 2016
13
0101000010100111 = ?
• Humans can’t work well with binary numbers;
there are too many digits to deal with.
• Memory addresses and other data can be
quite large. Therefore, we sometimes use the
hexadecimal number system.
UMBC CMSC 104, Section 01 - Fall 2016
14


The hexadecimal number system is also
known as base 16. The values of the positions
are calculated by taking 16 to some power.
Why is the base 16 for hexadecimal numbers ?
 Because we use 16 symbols, the digits 0
through 9 and the letters A through F.
UMBC CMSC 104, Section 01 - Fall 2016
15
Binary
Decimal
Hexadecimal
0
0
0
1
1
1
10
2
2
11
3
3
100
4
4
101
5
5
110
6
6
111
7
7
1000
8
8
1001
9
9
1010
10
A
1011
11
B
1100
12
C
1101
13
D
1110
14
E
1111
15
F
UMBC CMSC 104, Section 01 - Fall 2016
16

Example of a hexadecimal number and the
values of the positions:
3 C 8 B 0 5 1
166 165 164 163 162 161 160
UMBC CMSC 104, Section 01 - Fall 2016
17
Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 12
Decimal: 2064710
Hexadecimal: 50A716
Notice how the number of digits gets
smaller as the base increases.
UMBC CMSC 104, Section 01 - Fall 2016
18

Because both Hex and Binary are based on
powers of two, converting from Binary to Hex
(or Hex to Binary) is simple.
Binary: 1 1 1 1 0 1 0 0 1 0 1 1 1 1 0 12
Hex
F
UMBC CMSC 104, Section 01 - Fall 2016
4
B
D
16
19


Same principals as before…
Try converting this hexadecimal value to decimal
3 A F 9 . B16
B X 16-1 =
.69
163 162 161 160 16-1
9 X 160 =
9
F X 161 =
240
A X 162 = 2560
3 X 163 = 12288
15097.6910
UMBC CMSC 104, Section 01 - Fall 2016
20
• Make a list of the hex place values up to the number
being converted.
• Perform successive divisions by 16, placing the remainder
in each of the positions from right to left.
• Continue until the quotient is zero.
• Example: 34710
162
256
1
161 160
16
1
5
B
UMBC CMSC 104, Section 01 - Fall 2016
21


The logic we’ve applied goes for any arbitrary
number system
What would a base 7 number system look like?
5 6 2 1 . 47
4 X 7-1 = .57
73 72 71 70 7-1
1 X 70 =
1
2 X 71 =
14
6 X 72 = 294
5 X 73 = 1715
2024.5710
UMBC CMSC 104, Section 01 - Fall 2016
22
UMBC CMSC 104, Section 01 - Fall 2016
23

From Decimal to Binary
 19
 89
 234

From Binary to Decimal
 0001 1101
 1001 0110
 0111 0001
UMBC CMSC 104, Section 01 - Fall 2016
24

From Decimal to Binary
 19 = 0001 0011
 89 = 0101 1001
 234 = 1110 1010

From Binary to Decimal
 0001 1101 = 29
 1001 0110 = 150
 0111 0001 = 113
UMBC CMSC 104, Section 01 - Fall 2016
25

From Decimal to Hex
 116
 516

From Hex to Decimal
 A7
 B0B
UMBC CMSC 104, Section 01 - Fall 2016
26

From Decimal to Hex
 116 = 74
 516 = 204

From Hex to Decimal
 A7 = 167
 B0B = 2827
UMBC CMSC 104, Section 01 - Fall 2016
27
28
27
26
25
24
23
22
21
20
128
64
32
16
8
4
2
1
UMBC CMSC 104, Section 01 - Fall 2016
29
163
162
161
160
4096
256
16
1
UMBC CMSC 104, Section 01 - Fall 2016
30