Digital Logic Design - CH 2
Digital Logic Design - CH 2
Chapter 2
Number System,
Operations and Codes
Content
• Decimal Numbers
• Binary Numbers
• Binary to Decimal Conversion
• Decimal to Binary Conversion
• Binary Arithmetic
• 1'S AND 2’S Complement of Binary Numbers
• Signed Binary Number
• Arithmetic Operations with Signed Numbers
• Hexadecimal Number
• Octal Number
• Binary Codded Decimal(BCD)
• Digital Code
1
Digital Logic Design
Decimal Numbers
Cont.
2
Digital Logic Design
Cont.…
• Example1:-
Binary Numbers
3
Digital Logic Design
Cont.
• The weights increase from right to left by a power of two for
each bit.
• The left-most bit is the MSB (most significant bit).
• The left-most bit is the MSB in a binary fractional number
and has a weight of 2-1= 0.5.
• The fractional weights decrease from left to right by a
negative power of two for each bit.
• Generally, the weight structure of a binary number is
• where n is the number
of bits from the binary
point.
Decimal Binary
Binary Counting Number
0
Number
0000
1 0001
• A binary counting sequence for numbers 2 0010
from zero to fifteen is shown. 3 0011
4 0100
• Notice the pattern of zeros and ones in 5 0101
each column. 6 0110
7 0111
• Digital counters frequently have this
8 1000
same pattern of digits: 9 1001
Counter 0 1 0 1 0 1 0 1 0 1 Decoder
10 1010
0 0 1 1 0 0 1 1 0 0
11 1011
12 1100
0 0 0 0 1 1 1 1 0 0
13 1101
0 0 0 0 0 0 0 0 1 1
14 1110
15 1111
4
Digital Logic Design
Exercise
• Find the binary value of the decimal number 122
Binary Counting
• With n bits we can represent decimal numbers
from 0 to 2n – 1.
• How many bits do we need to conunt(represent) N
decimal numbers in a binary?
𝑛 ≥ log 𝑁
Where n is the numbers of bit needed (it is positive
integre)
• How many decimal numbers can we represent with
n bits binary number?
𝑁=2
10
5
Digital Logic Design
11
12
6
Digital Logic Design
Cont.
• Ex :-
13
a. Sum-of-Weights Method
• One way to find the binary number that is equivalent to a given
decimal number is to determine the set of binary weights whose
sum is equal to the decimal number.
Convert the decimal number 49 to binary.
The column weights double in each position to the right. Write
down column weights until the last number is larger than the
one you want to convert.
26 25 24 23 22 21 20.
64 32 16 8 4 2 1.
0 1 1 0 0 0 1.
Example:- Convert the following decimal numbers to binary:
a) 12 b)25 c)58 d)72
14
7
Digital Logic Design
15
Repeated
Division
Divide the decimal
number by 2.
Write the remainder
after each division
until a quotient of
zero is obtained.
The first remainder
is the LSB.
The last is the MSB.
16
8
Digital Logic Design
17
9
Digital Logic Design
19
Binary Arithmetic
Binary Addition
The rules for binary addition are
0+0=0 Sum = 0, carry = 0
0+1=1 Sum = 1, carry = 0
1+0=1 Sum = 1, carry = 0
1 + 1 = 10 Sum = 0, carry = 1
When an input carry = 1 due to a previous result, the rules
are
1 + 0 + 0 = 01 Sum = 1, carry = 0
1 + 0 + 1 = 10 Sum = 0, carry = 1
1 + 1 + 0 = 10 Sum = 0, carry = 1
1 + 1 + 1 = 11 Sum = 1, carry = 1
20
10
Digital Logic Design
Binary Arithmetic
Binary Addition
Add the binary numbers 00111 and 10101 and show
the equivalent decimal addition.
0111
00111 7
10101 21
11100 = 28
Add the following binary numbers
(a) 11+11 (b) 100+10 (c) 111+11 (d) 110+100
21
Binary Arithmetic
Binary Subtraction
The four rules for binary subtraction of bits are
0-0=0
1-1=0
1-0=1
10 - 1 = 1 0-1,with a borrow of 1
Subtract the binary number 00111 from 10101 and
show the equivalent decimal subtraction.
111
10101
/ / / 21
00111 7
01110 = 14
22
11
Digital Logic Design
Example
23
Binary Arithmetic
Binary Subtraction
Perform the following binary subtraction:
(a) 11 - 01 (b) 11 - 10
24
12
Digital Logic Design
Binary Arithmetic
Binary Multiplication
The four basic rules for multiplying bits are as follows:
0*0=0
0*1=0
1*0=0
1*1=1
Perform the following binary multiplications:
(a) 11 * 11 (b) 101 * 111
25
Binary Arithmetic
Binary Division
Division in binary follows the same procedure as division in
decimal.
26
13
Digital Logic Design
27
1’S Complement
0 0 1 1 0 1 0 1
28
14
Digital Logic Design
2’S Complement
1
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)
0 0 1 1 0 1 1 0
29
2’S Complement
30
15
Digital Logic Design
31
32
16
Digital Logic Design
Sign-Magnitude Form
• When a signed binary number is represented in sign-
magnitude, the left-most bit is the sign bit and the remaining
bits are the magnitude bits.
• The magnitude bits are in true (uncomplemented) binary for
both positive and negative numbers.
• For example, the decimal number + 25 is expressed as an 8-
bit signed binary number using the sign-magnitude form as
33
34
17
Digital Logic Design
35
Cont.…
Example
Express the decimal number -39 as an 8-bit number in the
a) sign-magnitude
b) 1's complement, and
c) 2's complement forms.
36
18
Digital Logic Design
37
38
19
Digital Logic Design
Binary-to-Hexadecimal Conversion
39
Hexadecimal-to-Binary Conversion
40
20
Digital Logic Design
Hexadecimal-to-Decimal Conversion
41
Hexadecimal Addition
42
21
Digital Logic Design
Hexadecimal Subtraction
43
OCTAL NUMBERS
44
22
Digital Logic Design
45
Octal-to-Binary Conversion
Because each octal digit can be represented by a 3-bit
binary number, it is very easy to convert from octal to
binary.
46
23
Digital Logic Design
OCTAL TO BINARY
47
Binary-to-Octal Conversion
48
24
Digital Logic Design
Exercise
49
Human Perception
• We naturally live in a base 10 environment(decimal number
system)
• Computer exist in a base 2 environment(binary number system)
• So give the computer/digital system the task of doing the
conversions for us.
50
25
Digital Logic Design
Binary Codes
• “An n-bit binary code is a group of n bits that assume up to
2n distinct combinations of 1s and 0s, with each
combination representing one element of the set being
coded”
• For the 10 digits need a 4 bit code.
• The four bits code representation of decimal number is
called Binary Coded Decimal (BCD)
51
52
26
Digital Logic Design
53
Decimal to BCD
• To express any decimal number in BCD, simply replace each
decimal digit with the appropriate 4-bit code, as shown by
Example:
• Example:-Convert each of the following decimal numbers to
BCD: (a) 35 (b)98 (c) 170 (d)2469
54
27
Digital Logic Design
BCD to Decimal
It is equally easy to determine a decimal number from a BCD
number.
Start at the right most bit and break the code into groups of four
bits.
Then write the decimal digit represented by each 4-bit group.
Example:-Convert each of the following BCD codes to decimal:
55
Digital Codes
• Many specialized codes are used in digital systems.
• You have just learned about the BCD code; now let's look at a few
others.
• Some codes are strictly numeric, like BCD, and others are
alphanumeric; that is, they are used to represent numbers,
letters, symbols, and instructions.
• The codes introduced in this section are
The Gray code
The ASCII code and
56
28
Digital Logic Design
Gray Code
• The Gray code is unweighted and is not an arithmetic code; that is,
there are no specific weights assigned to the bit positions.
• The important feature of the Gray code is that it exhibits only a
single bit change from one code word to the next in sequence.
• Like binary numbers, the Gray code can have any number of bits.
Notice the single-bit change between successive Gray code words.
• Gray code is used to avoid problems in systems where an error
can occur if more than one bit changes at a time.
• This property is important in many applications, such as shaft
position encoders, where error susceptibility increases with the
number of bit changes between adjacent numbers in a sequence.
57
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
58
29
Digital Logic Design
59
60
30
Digital Logic Design
61
62
31
Digital Logic Design
63
Cont.…
64
32
Digital Logic Design
65
Alphanumeric Codes
• Alphanumeric codes are codes that represent numbers and
alphabetic characters (letters).
• Most such codes, however, also represent other characters
such as symbols and various instructions necessary for
conveying information that are found on a computer
keyboard.
• The ASCII is the most common alphanumeric code.
• ASCII:-is the abbreviation for American Standard Code for
Information Interchange.
66
33
Digital Logic Design
ASCII
ASCII is a universally accepted alphanumeric code used in most
computers and other electronic equipment.
Most computer keyboards are standardized with the ASCII.
When you enter a letter, a number, or control command, the
corresponding ASCII code goes into the computer.
ASCII has 128 characters and symbols represented by a 7-bit binary
code.
Actually, ASCII can be considered an 8-bit code with the MSB always 0.
This 8-bit code is 00 through 7F in hexadecimal.
The following table is a listing of partial ASCII code showing the decimal,
hexadecimal, and binary representations for each character and symbol.
67
68
34
Digital Logic Design
Cont.…
• Example:- The following is a message encoded in ASCII code. What is
the message? 1001000 1000101 1001100 1010000
• Solution:- Convert each seven-bit code to its hex equivalent.
• The results are 48 45 4C 50
• Now locate these hex values in Table above and determine the
character represented by each. The results are HELP
69
Extended ASCII
• In 1981, IBM introduced extended ASCII, which is
an 8-bit code and increased the character set to
256.
• Other extended sets (such as Unicode) have been
introduced to handle characters in languages other
than English.
70
35
Digital Logic Design
Parity Method
• The parity method is a method of error detection for
simple transmission errors involving one bit (or an odd
number of bits).
• A parity bit is an “extra” bit attached to a group of bits
to force the number of 1’s to be either even (even
parity) or odd (odd parity).
The ASCII character for “a” is 1100001 and for “A” is
1000001. What is the correct bit to append to make both of
these have odd parity?
The ASCII “a” has an odd number of bits that are equal to 1;
therefore the parity bit is 0. The ASCII “A” has an even
number of bits that are equal to 1; therefore the parity bit is 1.
71
36