Professional Documents
Culture Documents
Digital Logic Design More Number Systems/Complements
Digital Logic Design More Number Systems/Complements
Lecture 2
1
Understanding Octal Numbers
2
Understanding Binary Numbers
3
Why Use Binary Numbers?
° Easy to represent 0 and 1 using
electrical values.
° Possible to tolerate noise.
° Easy to transmit data
° Easy to build binary circuits.
AND Gate
1
0
0
4
001 = 1
Binary
010 = 2
011 = 3
In Binary, there are only 0’s and 1’s. These numbers are called “Base-2” ( Example: 0102)
110 = 6
° Each digit is one of two numbers:
111 = 7 0 and 1
Binary to
6
A Simple Switch
Vcc Vcc
Vcc, or 1 Gnd, or 0
7
Binary digits
Bit
100101112
Radix
Byte
8
Conversion Between Number Bases
Octal(base 8)
Hexadecimal
° (base16)
Learn to convert between bases.
° Already demonstrated how to convert from
binary to decimal.
° Hexadecimal described in next section
9
Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
10
Conversion Among Bases
The possibilities:
Decimal Octal
Binary Hexadecimal
11
Convert an Integer from Decimal to Another Base
12
Convert an Fraction from Decimal to Another Base
13
The Growth of Binary Numbers
n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024
3 23=8 11 211=2048
4 24=16 12 212=4096
Giga
6 26=64 30 230=1G
Tera
7 2 =128
7
40 2 =1T
40
14
Binary Addition
1 1 1 1 1 1 carries
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
1 0 1 0 1 0 0
15
Binary Subtraction
1 10 borrows
0 10 10 0 0 10
1 0
0 1 1 0 1
- 1 0 1 1 1
------------------------
1 1 0 1 1 0
16
Binary Multiplication
1 0 1
1 1
X 1 0 1 0
-----------------------
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1
-----------------------
1 1 1 0 0 1 1 0
17
Convert an Integer from Decimal to Octal
18
Convert an Fraction from Decimal to Octal
19
Overview
° Hexadecimal numbers
• Related to binary and octal numbers
° Why binary?
20
Understanding Binary Numbers
23
Converting Between Base 16 and Base 2
° Conversion is easy!
Determine 4-bit value for each hex digit
° Note that there are 24 = 16 different values of four bits
° Easier to read and write in hexadecimal.
° Representations are equivalent!
24
Converting Between Base 16 and Base 8
=[1276]10
26
Number systems (Octal
( Numbers)
5 4 7
27
Number systems (Octal
( Numbers)
Binary Decimal
110 6
101 5
110 101 = (65)8
{
{
6 5
28
Number systems (Octal
( Numbers)
Binary Decimal
1 001
3 011
(13)8 = (001011)2
29
Radix Based Conversion (Example)
Radix 8 Answer
8 1234
8 154 2
Divide
8 19 2 23228
by radix 8
2 3
30
Octals
2 1 0
2 0 78
= 13510
31
Hexadecimal
° Hexadecimal is used to simplify dealing with large binary values:
• Base-16, or Hexadecimal, has 16 characters: 0-9, A-F
• Represent a 4-bit binary value: 00002 (0) to 11112 (F)
• Easier than using ones and zeros for large binary values
• Commonly used in computer applications
° Examples:
• 11002 = 1210 = C16
• 1010 0110 1100 00102 = A6 C216
Hex values can be followed by an “H” to indicate base-16. Example: A6 C2 H
32
Hex Values in Computers
33
Decimal to Hexadecimal
Decimal Hex
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F
34
Conversion Binary to Hexadecimal
1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0
A C 1 6
35
Radix Based Conversion (Example)
Radix 16 Answer
16 1234
Divide
16 77 2
4D216
by radix 16 4 D
36
Hexadecimals – Base 16
2 1 0
2 E A 16
= 74610
37
Octal to Hex Conversion
38
Hex to Octal Conversion
Ex : Convert E8A16 to octal
First convert the hex to binary:
1110 1000 10102
39
Octal to Hex Conversion
Ex : Convert 7528 to hex
First convert the octal to binary:
111 101 010re-group
2 by 4 bits
So 7528 = 1EA16
40
Octal to Hexadecimal
Decimal Octal
Binary Hexadecimal
41
Octal to Hexadecimal
° Technique
• Use binary as an intermediary
42
Example
10768 = ?16
1 0 7 6
2 3 E
10768 = 23E16
43
Hexadecimal to Octal
Decimal Octal
Binary Hexadecimal
44
Hexadecimal to Octal
° Technique
• Use binary as an intermediary
45
Example
1F0C16 = ?8
1 F 0 C
1 7 4 1 4
1F0C16 = 174148
46
Example: Hex → Octal
Example:
0
80 + 10 = 9010 8 1 r 1 MSB
5AH = 1328
47
Fractions (Example)
48
Fractions (Example)
49
Radix Based Conversion (Example)
Radix 2
Multiply by radix 2
50
Radix Based Conversion (Example)
Answer 0.835316
51
°Lecture 03
°2’s Complement
52
How To Represent Signed Numbers
• Plus and minus sign used for decimal numbers: 25
(or +25), -16, etc.
• For computers, desirable to represent everything as
bits.
• Three types of signed binary number representations:
signed magnitude, 1’s complement, 2’s complement.
• In each case: left-most bit indicates sign: positive (0)
or negative (1).
Consider signed magnitude:
000011002 = 1210 100011002 = -1210
53
Complement
° It has already been studied that
° subtracting one number from another is the same as making one
number negative and just adding them.
° We know how to create negative numbers in the binary number
system.
° How to perform 2’s complement process.
° How the 2’s complement process can be use to add (and subtract)
binary numbers.
° Digital electronics requires frequent addition and subtraction of
numbers. You know how to design an adder, but what about a
subtracter?
° A subtracter is not needed with the 2’s complement process. The 2’s
complement process allows you to easily convert a positive number54
3-Digit Decimal
A bicycle odometer with only three
digits is an example of a fixed-
999
length decimal number system. forward (+)
998
55
Negative Decimal
+499 499
How do we represent negative pos(+)
+498 498
numbers in this 3-digit decimal
+497 497
number system without using a
sign?
+001 001
3 003 6 006
+ 2 + 002 + (-3) + 997
5 005 3 1003
Disregard
Overflow
It Works!
57
Complex Problem
58
Complement
59
10’s Complement Examples
Example #1
-003 Complement Digits
996
+1 Add 1
997
Example #2
-214
Complement Digits
785
+1 Add 1
60
One’s Complement Representation
• The one’s complement of a binary number involves
inverting all bits.
• 1’s comp of 00110011 is 11001100
• 1’s comp of 10101010 is 01010101
• For an n bit number N the 1’s complement is (2n-1) –
N.
• Called diminished radix complement by Mano since
1’s complement for base (radix 2).
• To 00001100
find negative
= 12 of 1’s complement number take the
11110011 = -12
1’s complement.
2 10 2 10
61
Two’s Complement Representation
• The two’s complement of a binary number involves
inverting all bits and adding 1.
• 2’s comp of 00110011 is 11001101
• 2’s comp of 10101010 is 01010110
• For an n bit number N the 2’s complement is (2n-1) – N
+ 1.
• Called radix complement by Mano since 2’s
complement for base (radix 2).
• To 00001100
find negative
= 12 of 2’s complement number take the
11110100 = -12
2’s complement.
2 10 2 10
62
Two’s Complement Shortcuts
° Algorithm 1 – Simply complement each bit and then add 1
to the result.
• Finding the 2’s complement of (01100101)2 and of its 2’s complement…
N = 01100101 [N] = 10011011
10011010 01100100
+ 1 + 1
--------------- ---------------
10011011 01100101
Ignore
67
2’s Complement Subtraction
° Using 2’s complement numbers, follow steps for
subtraction
° For example, suppose we wish to subtract +(0001)2 from
+(1100)2. 0 1 1 0 0
° Let’s compute (12)10 - (1)10. - 0 0 0 0 1
• (12) = +(1100) = 01100 in 2’s comp.
--------------
10 2 2 2’s comp
68
2’s Complement Subtraction: Example #2
71
2’s Complement
72
Overflow
° Overflow conditions
° Add two positive numbers to get a negative number
° Add two negative numbers to get a positive number
73
Two’s Complement Number System
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
0
- 1 1
0000
1111 0001 2
- 2
1110 0010
- 3 3
1101 0011
- 4 4
1100 0100
5
1011 0101
- 5
1010 0110
- 6 6
1001 1000 0111
- 7 - 7
8 74
Summary
75
Summary
76