UTF-8''Digital Fundamentals Tenth Edition Floyd-Chapter 2
UTF-8''Digital Fundamentals Tenth Edition Floyd-Chapter 2
Lecture 2
1
DIGITAL
FUNDAMENTALS
Tenth Edition
Floyd
Chapter 2
© 2008 Pearson
Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. l Rights Reserved
Al Education
Content:
• Decimal Numbers
• Binary Numbers
• 1’s Complement
• 1’s Complement
• Signed Binary Numbers
• Floating Point Numbers
• Hexadecimal Numbers
• Octal Numbers
• BCD
• Gray code
• ASCII
• Parity Method
• Cyclic Redundancy Check
3
Decimal Numbers
Example:
10
14 1 10 1
0
Binary Conversions
You can convert decimal to any other base by repeatedly dividing by the base.
For binary, repeatedly divide by 2:
You can do this by “reverse division” and the answer will read from left to
right. Put quotients to the left and remainders on top.
Answer: 1 1 0 0 0 remainder
0 1 1 3 6
12 24 49 2 base
13
Binary Addition
14
Binary Subtraction
The rules for binary subtraction are
00=0
11=0
10=1
10 1 = 1 with a borrow of 1
15
1’s Complement
0 0 1 1 0 1 0 1
16
2’s Complement
The 2’s complement of a binary number is found by
adding 1 to the least significant bit (LSB) of the 1’s
complement.
Recall that the 1’s complement of 11001010 is
00110101 (1’s
To form the 2’s complement, add 1: complement)+1
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add
Output bits (sum) 1)
00 1 1 0 1
17
1 0
Signed Binary Numbers
There are several ways to represent signed binary numbers.
In all cases, the MSB in a signed number is the sign bit,
that tells you if the number is positive or negative.
Computers use a modified 2’s complement for
signed numbers. Positive numbers are stored in true form
(with a 0 for the sign bit) and negative numbers are
stored in complement form (with a 1 for the sign bit).
For example, the positive number 58 is written
using 8-bits as 00111010 (true form).
10112.
Arithmetic Operations with Signed Numbers
Using the signed number notation with negative
numbers in 2’s complement form simplifies addition
and subtraction of signed numbers.
Rules for addition: Add the two signed numbers.
Discard any final carries. The result is in signed form.
Examples:
00011110 = +30 00001110 = +14 11111111 = 1
00001111 = +15 11101111 = 17 11111000 = 8
00101101 = +45 11111101 = 3 111110111 = 9
Discard carry
21
Arithmetic Operations with Signed Numbers
Note that if the number of bits required for the answer
is exceeded, overflow will occur. This occurs only if
both numbers have the same sign. The overflow will be
indicated by an incorrect sign bit.
Two examples are:
0 000000 = +128 10000001 =
1 127
0
10000001
000001 =
= +129
126 Discard carry 10000001 =
100000010 = +2
1 127
Wrong! The answer is
incorrect and the sign bit has
changed. 22
Arithmetic Operations with Signed Numbers
Rules for subtraction: 2’s complement the subtrahend and
add the numbers. Discard any final carries. The result is
in signed form.
Repeat the examples done previously, but subtract:
00011110 (+30) 11111111 (1)
00001110
00001111 (+14)
–(+15) 11101111 –(17) 11111000 –
(8)
00011110 = +30 00001110 = +14 11111111 = 1
2’s complement
11110001 = 15subtrahend and=add:
00010001 +17 00001000 = 8
100001111 = +15 00011111 = +31 100000111 = +7
Discard carry Discard carry
23
Decimal Hexadecimal Binary
Hexadecimal Numbers 0 0
0000
Hexadecimal uses sixteen characters 1 1
to represent numbers: the numbers 0 0001
through 9 and the alphabetic 2 2
characters A through F. 0010
3 3
Large binary number can easily 0011
be converted to hexadecimal by 4 4
grouping bits 4 at a time and writing 0100
the equivalent hexadecimal character. 5 5
0101
Express 1001 0110 0000 11102 in 6 6
hexadecimal: 0110
Group the binary number by 4- 7 7
bits starting from the right. Thus, 0111 24
960E 8 8
1000
Decimal Hexadecimal Binary
Hexadecimal Numbers 0 0 0000
1 1 0001
Hexadecimal is a weighted number 2 2 0010
system. The column weights are 3 3 0011
powers of 16, which increase from 4 4 0100
5 5 0101
right to left. 6 6 0110
{
Column weights
163 162 161 160.
4096 256 16 1 .
7
8
7
8
0111
1000
9 9 1001
Express 1A2F16 in decimal. 10 A 1010
11 B 1011
Start by writing the column weights: 12 C 1100
4096 256 16 1
13 D 1101
1 A 2 16
14 E 1110
F +2(16) +15(1) = 670310
1(4096) + 10(256) 15 F 1111
25
Decimal Octal Binary
Octal Numbers 0 0 0000
1 1 0001
Octal uses eight characters the 2 2 0010
numbers 0 through 7 to represent 3 3 0011
numbers. 4 4 0100
There is no 8 or 9 character in octal. 5 5 0101
6 6 0110
Binary number can easily be 7 7 0111
converted to octal by grouping bits 3 8 10 1000
at a time and writing the equivalent 9 11 1001
octal character 10 12 1010
Express 1for each
001 011 group.
000 001 1102 in
11 13 1011
octal:
12 14 1100
Group the binary number by 3-bits 13 15 1101
starting from the right. Thus, 1130168 14 16 1110
15 17 1111
26
Decimal Octal Binary
Octal Numbers 0 0 0000
1 1 0001
Octal is also a weighted number 2 2 0010
system. The column weights are 3 3 0011
powers of 8, which increase from right 4 4 0100
5 5 0101
to left. 6 6 0110
{
Column weights
83
512 64
82 81
8
80 .
1 .
7
8
7
10
0111
1000
9 11 1001
Express 37028 in decimal. 10 12 1010
11 13 1011
Start by writing the column weights: 12 14 1100
512 64 8 1
13 15 1101
3 7 0 28
14 16 1110
3(512) + 7(64) +0(8) +2(1) = 198610 15 17 1111 27
Decimal Binary BCD
BCD 0 0000
0000 0001
Binary coded decimal (BCD) is a 1 0010
weighted code that is commonly 0001 0011
used in digital systems when it is 2
4 0100
0010
0100 0101
necessary to show decimal 5
3 0011 0110
numbers such as in clock displays. 0101 0111
The table illustrates the 6 0110 1000
difference between straight binary 7 0111 1001
and BCD. BCD represents each 8 1000 00010000
digit with a 4-bit code. Notice that the
decimal 11
9 00010001
codes 1010 through 1111 are not used in 1011
1001 00010010
BCD. 12
10 00010011
1100
1010 00010100
13 0001010128
1101
14 1110
BCD
30
Decimal Binary Gray code
Gray code 0 0000
0000 0001
Gray code is an unweighted code 1 0011
that has a single bit change 0001 0010
one code word and the next in a
between 2
4 0110
0010
0100 0111
sequence. Gray code is used to 5
3 0011 0101
avoid problems in systems where an 0101 0100
error can occur if more than one bit 6 0110 1100
changes at a time. 7 0111 1101
8 1000 1111
11
9 1110
1011
1001 1010
12
10 1011
1100
1010 1001
13 1000 31
1101
14 1110
Gray code
A shaft encoder is a typical application. Three IR
emitter/detectors are used to encode the position of the shaft.
The encoder on the left uses binary and can have three bits
change together, creating a potential error. The encoder on
the right uses gray code and only 1-bit changes, eliminating
potential errors.
Binary sequence
Gray code sequence
32
ASCII
35
SELECTED KEY TERMS
36
SELECTED KEY TERMS
38
2. The 2’s complement of 1000 is
a. 0111
b. 1000
c. 1001
d. 1010
39
3. THE FRACTIONAL BINARY NUMBER 0.11 HAS A
DECIMAL VALUE OF
a. ¼
b. ½
c. ¾
d. none of the above
40
4. The hexadecimal number 2C has a decimal equivalent
value of
a. 14
b. 44
c. 64
d. none of the above
41
5. Assume that a floating point number is represented
in
binary. If the sign bit is 1, the
a. number is negative
b. number is positive
c. exponent is negative
d. exponent is positive
42
6.When two positive signed numbers are added, the result
may be larger that the size of the original numbers,
creating overflow. This condition is indicated by
a. a change in the sign bit
b. a carry out of the sign position
c. a zero result
d. smoke
43
7. The number 1010 in BCD is
a. equal to decimal eight
b. equal to decimal ten
c. equal to decimal twelve
d. invalid
44
8. An example of an unweighted code is
a. binary
b. decimal
c. BCD
d. Gray code
45
9. An example of an alphanumeric code is
a. hexadecimal
b. ASCII
c. BCD
d. CRC
46
10. An example of an error detection method for
transmitted data is the
a. parity check
b. CRC
c. both of the above
d. none of the above
47
Answers:
1. c 6. a
2. b 7. d
3. c 8. d
4. b 9. b
5. a 10.
48
c
? 49