Lecture 2

advertisement
+
CS 325: CS Hardware and Software
Organization and Architecture
Integers and Arithmetic
2/4/2016
1
+
Outline
 Number
Representation
Decimal
 Binary
 Hexadecimal

 Decimal
vs. Hexadecimal vs. Binary
 Number
Conversions
Dec  Bin, Dec  Hex
 Bin  Dec, Bin  Hex
 Hex  Dec, Hex  Bin

2
+
3
Common Number Systems
System
Base
Symbols
Used by
Used in
humans? computers?
Decimal
10
0, 1, … 9
Yes
No
Binary
2
0, 1
No
Yes
Octal
8
0, 1, … 7
No
No
Hexadecimal
16
0, 1, … 9,
A, B, … F
No
No
+
4
Quantities/Counting (1 of 3)
HexaDecimal Binary Octal decimal
0
1
2
0
1
10
0
1
2
0
1
2
3
4
5
6
11
100
101
110
3
4
5
6
3
4
5
6
7
111
7
7
+
5
Quantities/Counting (2 of 3)
HexaDecimal Binary Octal decimal
8
9
10
1000
1001
1010
10
11
12
8
9
A
11
12
13
14
1011
1100
1101
1110
13
14
15
16
B
C
D
E
15
1111
17
F
+
6
Quantities/Counting (3 of 3)
HexaDecimal Binary Octal decimal
16
17
18
10000
10001
10010
20
21
22
10
11
12
19
20
21
22
10011
10100
10101
10110
23
24
25
26
13
14
15
16
23
10111
27
17
+
7
Conversion Among Bases
• The Possibilities:
Decimal
Octal
Binary
Hexadecimal
+
8
Decimal Numbers: Base 10

Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Example:
4923 =
(4x103) + (9x102) + (2x101) + (3x100)
+
9
Number Base:

Number with base x  x digits:
 Base
10 (Decimal): 0, 1, 2, 3, 4 ,5 ,6 ,7 , 8, 9
 Base 2 (Binary): 0, 1
 Number
representation:
 d31d30d29….d2d1d0
 4326210
is a 32 digit number
is a 5 digit base 10 (Dec) number
 101011010112 is a 11 digit base 2 (Bin) number
+
10
Binary Numbers: Base 2

Digits: 0, 1
Example:
101011=
(1x25) + (0x24) + (1x23) + (0x22) + (1x21) + (1x20)
32
16
8
4
2
1
25
24
23
22
21
20
1
0
1
0
1
1
= 4310
 What about a base that converts to binary easily?
+
11
Hexadecimal Numbers: Base 16

Digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
 Decimal digits + A – F
A
B
C
D
E
F
10
11
12
13
14
15
Example:
12E =
(1x162) + (2x161) + (Ex160) = 30210
+
12
Decimal vs. Hexadecimal vs. Binary
DEC
HEX
BIN
DEC
HEX
BIN
0
0
0000
16
10
0001 0000
1
1
0001
17
11
0001 0001
2
2
0010
18
12
0001 0010
3
3
0011
19
13
0001 0011
4
4
0100
20
14
0001 0100
5
5
0101
21
15
0001 0101
6
6
0110
22
16
0001 0110
7
7
0111
23
17
0001 0111
8
8
1000
24
18
0001 1000
9
9
1001
25
19
0001 1001
10
A
1010
26
1A
0001 1010
11
B
1011
27
1B
0001 1011
12
C
1100
28
1C
0001 1100
13
D
1101
29
1D
0001 1101
14
E
1110
30
1E
0001 1110
15
F
1111
31
1F
0001 1111
+
13
Number Conversion: Dec  Bin

Converting from base 10 to base 2:
Continue dividing decimal number by
2 and keep the remainder
Example:
1000112
3510
35/2
17
1
17/2
8
1
8/2
4
0
4/2
2
0
2/2
1
0
1/2
0
1
LSB
MSB
+
14
Number Conversion: Dec  Bin

Example:
 Convert
42310 to Bin
1101001112
+
15
Number Conversion: Dec  Hex

Converting from base 10 to base 16:

Example:
2316
3510
35/16
2
3
LSB
2/16
0
2
MSB
+
16
Number Conversion: Dec  Hex

Example:
 Convert
21010 to Hex
D216
+
17
Number Conversion: Bin  Dec

Converting from base 2 to base 10:

Example: 110102
(1x24) + (1x23) + (0x22) + (1x21) + (0x20)
16 + 8 + 0 + 2 + 0 = 2610
16
8
4
2
1
1
1
0
1
0
MSB
LSB
+
18
Number Conversion: Bin  Dec

Example:
 Convert
101011102 to Dec
17410
+
19
Number Conversion: Bin  Hex

Converting from base 2 to base 16:

Example: 110101102



1 Hex digit represents 16 Decimal values
4 Binary digits represent 16 Decimal values
1 Hex digit replaces 4 Binary digits
1
1
0
1
0
13  D
1
1
6
D616
0
+
20
Number Conversion: Bin  Hex

Example:
 Convert
110011112 to Hex
CF16
+
21
Number Conversion: Hex  Dec

Converting from base 16 to base 10:

Example: 8E316
(8x162) + (Ex161) + (3x160)
2048 + 224 + 3 = 227510
+
22
Number Conversion: Hex  Dec

Example:
 Convert
63F16 to Dec
159910
+
23
Number Conversion: Hex  Bin

Converting from base 16 to base 2:

Example: 9A2E16
9
1001
A
1010
2
0010
E
1110
10011010001011102
MSB
LSB
+
24
Number Conversion: Hex  Bin

Example:
 Convert
26FA16 to Bin
100110111110102
+
25
Exercise – Number Conversions
Decimal
33
Binary
Octal
Hexadecimal
1110101
703
1AF
Don’t use a calculator!
+
26
Exercise – Number Conversions
Hexadecimal
Decimal
33
Binary
100001
Octal
41
117
1110101
165
75
451
111000011
703
1C3
431
110101111
657
1AF
21
+
27
What to do with representations of
numbers?

add, subtract, multiply, divide, compare
 Example:
8 + 6 = 14
1
0
0
0
+0
1
1
0
1
1
1
0
Simple enough to add in binary that we
can build circuits to do it.
+
28
Which base do we use?

Decimal: Great for human, especially
when doing arithmetic
Hex:
Easier for humans to read than long
strings of binary numbers. Easy to convert
to binary, each hex decimal = 4 binary bits.
Binary:
used by all computers. Bin
represents an abstraction…but an
abstraction of what?
+
29
The Transistor

A controlled switch.
 Collector
– positive lead
 Emitter – negative lead
 Base – control lead
A
binary “1” represents an
active transistor.
+
30
The Transistor
+
31
Limits of Computer Numbers

Bits can represent anything
 Characters
 ‘a’, ‘F’
7
bit ASCII, 8 bit Extended ASCII
 Logical Values
 0  False, 1 True
 Colors?
 Locations/addresses? Commands?
 N bits  2N number of things
Download