Вы находитесь на странице: 1из 52

Chapter 1

Digital Systems and Binary Numbers

Course title: Digital Logic Design


Course code: EEE241
Instructor: Dr. Ashfaq Ahmed

1
Course Description
Marks distribution (theory & lab)
Finals : 50%
Sessional : (10+15)%
Quizzes/Assignments : 25%

Total marks : 0.75*(Marks in theory) +


0.25*(Marks in lab)
Mandatory to get >50% in total, including
>50% in theory and lab individually

2 Digital Logic Design by Dr. Ashfaq Ahmed


Quizzes/Assignments
Quiz/
Assignme Week Class
nt

1 6~10 March 1st

2 27~31 April 1st

3 3~7 April 1st

4 15~19 May 1st


Note: Assignment will be given one week before the shown da

3 Digital Logic Design by Dr. Ashfaq Ahmed


Disclaimer!
The slides of this course are
mainly produced from
Digital Design with an
Introduction to
Verilog HDL, 5th Edition
by
M. Morris Mano & Michael D.
Ciletti
4 Digital Logic Design by Dr. Ashfaq Ahmed
Digital Systems
Describes any system based on
discontinuousdataor events1
Used in communication, business
transactions, traffic control, spacecraft
guidance, medical treatment, weather
monitoring, internet etc.
Is an interconnection of digital modules
To understand the operation of each digital
module, it is necessary to have basic
knowledge of digital circuits and their
logic functions
1: http://www.webopedia.com/TERM/D/digital.html

5 Digital Logic Design by Dr. Ashfaq Ahmed


Binary Numbers
Decimal number 7,392 can be written as
7000+300+90+2, or other way around it
can be
In general we can write as
The coefficient are any of the 10 digits
(0~9) and the subscript value shows the
position (also the power of 10 by which the
coefficient has to be multiplied)
Therefore the preceding decimal number
can be represented as,

6 Digital Logic Design by Dr. Ashfaq Ahmed


Binary Numbers (2)
Decimal
numbers is said to be of base, or radix,
10 because the number contains the 10 digits
(0~9) and are multiplied by the power of 10
Similarly, binary numbers is said to be of base,
or radix, 2 because the number contains the 2
digitals (0~1) and are multiplied by the power of
2
Each binary coefficient is multiplied by , where
shows the position, and finally produces the
decimal counterpart of the binary number. and
are the positions of the most significant and the
least significant bits of the binary number

7 Digital Logic Design by Dr. Ashfaq Ahmed


Binary Numbers (3)
Example:

Hence,

8 Digital Logic Design by Dr. Ashfaq Ahmed


Other Number Systems
Keeping in mind the previous discussion,
any number system can be seen in base-r
as
+ + ++ ++++
Any number represented in base-r will
contain the coefficients from (0~r-1)
Example:
++

9 Digital Logic Design by Dr. Ashfaq Ahmed


Other Number Systems (2)
Octal number system are of base-8 and
contains digits from (0~7)
Example:
++

10 Digital Logic Design by Dr. Ashfaq Ahmed


Other Number Systems (3)
For the number with base greater than
10, we need some borrowed alphabets.
For example, hexadecimal number
(base-16) has digitals between (0~15),
where the digitals greater than 10 are
Representatio
Number
shown in table below:n
10 A
11 B
12 C
13 D
14 E
15 F

11 Digital Logic Design by Dr. Ashfaq Ahmed


Other Number Systems (3)
Example:
+

Hexadecimal (Hex) system is used to


represent long strings of bits in the
addresses, instructions, data in digital
systems.
Example:

12 Digital Logic Design by Dr. Ashfaq Ahmed


First Binary Numbers

0 1 8 256 16 65,536

1 2 9 512 17 131,072

2 4 10 1,024 (1K) 18 262,144

3 8 11 2,048 (2K) 19 524,288

4 16 12 4,096 (4K) 20 1,048,576 (1M)

5 32 13 8,192 21 2,097,152

6 64 14 16,384 22 4,194,304

7 128 15 32,768 23 8,388,608

13 Digital Logic Design by Dr. Ashfaq Ahmed


Data Representation
Number of Bits
1,024 1K
1,048,576 1M
1,073,741,824 1G
1,099,511,627,776 1T

1 byte = 8 bits

14 Digital Logic Design by Dr. Ashfaq Ahmed


Decimal to Base-r Conversion
Number with different base are considered
same, if they have same decimal
conversion, e.g.
Conversion of a number from any arbitrary
base-r to decimal one is discussed before
How to convert a decimal number to any
other base-r?
If a decimal number contains a decimal
point (fractional number), the integer and
the fractional parts will be solved
separately and differently
15 Digital Logic Design by Dr. Ashfaq Ahmed
Decimal to Base-r Conversion
(2)
Conversion from decimal number N to a
number M in base-r needs division of the N
and all the successive quotients by r and
accumulating the remainders
Divid Dividen Quotien Remain
er d t der
Example 1.1:
2 41 20 - 1
2 20 10 - 0
2 10 5 - 0
2 5 2 - 1
2 2 1 - 0
16 2
Digital Logic Design by Dr. Ashfaq Ahmed 1 0 - 1
Decimal to Base-r Conversion
(3)
Conversion from decimal number N to a
number M in base-r needs division of the N
and all the successive quotients by r and
accumulating the remainders
Example 1.2: Divide Quotie Remaind
Dividend
r nt er

8 153 19 - 1
8 19 2 - 3
8 2 0 - 2

17 Digital Logic Design by Dr. Ashfaq Ahmed


Decimal to Base-r Conversion
(4)
Example 1.3:

Divid Dividen Quotie Remain


er d nt der

8 41 5 - 1
8 5 0 - 5

18 Digital Logic Design by Dr. Ashfaq Ahmed


Decimal to Base-r Conversion
(4)
Example 1.4:

Multiplica Multiplican Integer


Result
nd1 d2 part

1.37
2 0.6875 - 1
50
0.75
2 0.3750 - 0
00
2 0.7500 1.5 - 1
19 Digital Logic Design by Dr. Ashfaq Ahmed
2 0.5 1 - 1
Decimal to Base-r Conversion
(5)
Example 1.5:

Multiplic Multiplica Integer


Result
and1 nd 2 part

4.10
8 0.513 - 4
4
0.83
8 0.104 - 0
2
6.65
8 0.832 - 6
6
20 Digital Logic Design by Dr. Ashfaq Ahmed 5.24
8 0.656 - 5
Decimal to Base-r Conversion
(6)
If and
It would means

If and
It would means

21 Digital Logic Design by Dr. Ashfaq Ahmed


Octal and Hexadecimal
Numbers
In an octal number, each digit corresponds
to 3 binary numbers (bits)
In a hex number, each digit corresponds to
4 binary numbers (bits)
Therefore conversion from binary to octal is
like:

Conversion from binary to Hex is like:

22 Digital Logic Design by Dr. Ashfaq Ahmed


Octal and Hexadecimal Numbers
(2)
Conversion from octal to binary like:

Conversion from Hex to binary like:

23 Digital Logic Design by Dr. Ashfaq Ahmed


Octal and Hexadecimal Numbers
(2)
Decimal (base 10) Binary (base 2) Octal (base 8) Hex (base 16)
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
24 Digital Logic
15 Design by Dr. Ashfaq
1111Ahmed 17 F
Complements of Numbers
Are used to simplify the subtraction process
Leads to simpler and less expensive circuits
Two types of compliments for each base-r
system:
1. Radix compliment (rs compliment)
2. Diminished radix compliment ((r-1)s
compliment)
For example, considering base-2, we will
call it 2s compliment and 1s compliment
Considering base-10, we will call it 10s
compliment and 9s compliment.
25 Digital Logic Design by Dr. Ashfaq Ahmed
Diminished Radix
Compliment
Given a number N in base-r having n digits, the
diminished radix compliment, i.e. (r 1)s
compliment is defined as (rn 1) N.
For a decimal number r = 10 and hence (r 1) =
9, so the 9s compliment of N will be (10n 1) N.
For example, if N = 243, it means n = 3. Now, the
diminished radix compliment of 243 will be (103
1) 243 = (1000 1) 243 = 999 243 = 756
In short, 9s compliment of any decimal number
can be obtained by subtracting its digits from all
9 digit number, e.g. 9s compliment of 546700
will be 999999 546700 = 453299

26 Digital Logic Design by Dr. Ashfaq Ahmed


Diminished Radix
Compliment (2)
For binary numbers, r = 2 and (r 1) = 1.
Now, the diminished radix compliment, i.e. 1s
compliment of a binary number N will be (2n 1) N
For example, for n = 4, 24 = (10000)2 and 24-1 =
(1111)2, thus the 1s compliment of any binary
number can be obtained by subtracting each digit
by all 1 binary number of length n-1
For example, 1s compliment of (1011000) 2 is
(1111111)2 - (1011000)2 = (0100111)2
Similarly, diminished radix compliment of octal and
hex number can be obtained by subtracting it from
7 or F, respectively

27 Digital Logic Design by Dr. Ashfaq Ahmed


Radix Compliment
Radix compliment, or rs compliment, of an n digit number
N in base-r is defined as rn N, for N 0
rs compliment can be obtained by added 1 to (r-1)s
compliment
For example, 10s compliment of 2389 is 7610 + 1 = 7611,
where 7610 is 9s compliment of 2389
Similarly, 2s compliment of (101100)2 is (010011)2 + 1 =
(010100)2, where (010011)2 is 1s compliment of (101100)2
If a number has a radix point, we need to remove the radix
point temporary, then have to find the radix compliment.
Finally the radix point is placed again the complimented
number at the same relative position (as in the original
number)
Compliment of compliment produces the number

28 Digital Logic Design by Dr. Ashfaq Ahmed


Simple Rule for Binary
Numbers!!!
1s compliment can be found by inverting
the bits, e.g. 1s compliment of (101100)2 is
(010011)2
2s compliment can be found by inverting
the bits and then adding 1 to the result,
e.g. 2s compliment of (101100)2 is
(010011)2 + (1)2 = (010100)2

29 Digital Logic Design by Dr. Ashfaq Ahmed


Subtraction with Compliment
Subtraction of two n digits number N and M
in base-r can be done in the following way,:
1. Add M to the rs compliment of N.
Mathematically, M + (rn N) = M N + rn
2. If M N, the sum will produce an end carry
which can be discarded
3. If M < N, the sum will never produce an
end carry and is equal to rn (M N). Take
the rs compliment of the sum and put a
negative sign in front

30 Digital Logic Design by Dr. Ashfaq Ahmed


Subtraction with Compliment
(2)
Example 1.6:
Using 10s compliment subtract 72532
3250

31 Digital Logic Design by Dr. Ashfaq Ahmed


Subtraction with Compliment
(3)
Example 1.7:
Using 10s complement, subtract 3250 -
72532.

As there is no end carry, therefore the


answer is (10s compliment of 30718) =
69282

32 Digital Logic Design by Dr. Ashfaq Ahmed


Subtraction with Compliment
(4)
Example 1.8:
Given the two binary numbers X = 1010100 and Y =
1000011, perform the subtraction (a) X Y and (b) Y X
by using 2s complements.

There is no end carry. Therefore,


the answer is Y - X = -(2s
33 Digital Logic Design by Dr. Ashfaq Ahmed
complement of 1101111) =
Signed Binary Numbers
A minus sign is used to represent a negative decimal
number
Binary numbers only contains 1s and 0s, therefore
a bit is required to represent a signed binary numbers
Usually a 0 bit at MSB is used to represent a positive
number and a 1 bit is used at MSB position to
represent a negative number
Example: Signed-magnitude representation
01001 represents +9 (signed) or 9 (unsigned)
11001 represents -9 (signed) or 25 (unsigned)
Usually used in ordinary arithmetic (not in computers
or machines)

34 Digital Logic Design by Dr. Ashfaq Ahmed


Signed Binary Numbers (2)
For computers, signed-magnitude notation is
not feasible
Signed-compliment is an alternate
representation for signed numbers
In signed-magnitude representation, a
number is negated by changing its sign,
whereas in signed-compliment representation
a number is negated by taking its compliment
Signed-compliment system can use either 1s
compliment or 2s complement, but 2s
compliment is most common

35 Digital Logic Design by Dr. Ashfaq Ahmed


Signed Binary Numbers (3)
Example: Three different representations of -9 in 8-
bits
Signed-magnitude
Binary representation of 9 in 8-bits is 00001001, where the
MSB represents the sign of the number, therefore it will
become 10001001
Signed-1s-compliment
Binary representation of 9 in 8-bits is 00001001. In order to
take 1s compliment, we just flip each bit and it becomes
11110110
Signed-2s compliment
Binary representation of 9 in 8-bits is 00001001. In order to
take 2s compliment, we find its 1s compliment first and then
add 1 to it. Therefore, 1s compliment will be 11110110 and
further 2s compliment will be 11110110 + 1 = 11110111

36 Digital Logic Design by Dr. Ashfaq Ahmed


Signed Binary Numbers (4)
Signed-
Decimal 1s Compliment 2s Compliment
Magnitude
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 1000 1111 -
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
-8 - - 1000
37 Digital Logic Design by Dr. Ashfaq Ahmed
Arithmetic Addition
Addition in signed-magnitude system
follows basic arithmetic rule, i.e. if both
operands have same sign, simply add them
and give the common sign to the sum
If any of the two operands is negative, we
need to subtract the smaller one from the
larger one and the result will get a negative
(sign of the larger number) sign
Addition in signed-magnitude system needs
a comparisons of the magnitudes and the
signs first, which makes it a bit complicated
38 Digital Logic Design by Dr. Ashfaq Ahmed
Arithmetic Addition (2)
In signed-compliment, we dont need to
compare the magnitudes and the signs,
instead we simply add (never subtraction)
the two complimented operands
Rule: The addition of two signed binary
numbers with negative numbers
represented in signed 2scomplement
form is obtained from the addition of the
two numbers, including their sign bits. A
carry out of the signbit position is
discarded.
39 Digital Logic Design by Dr. Ashfaq Ahmed
Arithmetic Addition (3)

40 Digital Logic Design by Dr. Ashfaq Ahmed


Arithmetic Addition (4)
Addition of two n-bits numbers can produce
a result with n+1-bits
Therefore, for addition of n-bits numbers,
we need a n+1-bits wide register to store
the complete result.

41 Digital Logic Design by Dr. Ashfaq Ahmed


Arithmetic Subtraction
Binary numbers in signed-compliment system
are added and subtracted by the same basic
rule (as defined in previous slides)
Therefore, the computer needs single
hardware to do both the operations
The user has to interpret the result of such
addition/subtraction differently
Example:
(-6) (-3) = +7
11111010 11110011 = 11111010 +
00001101 = 100000111 (+7)

42 Digital Logic Design by Dr. Ashfaq Ahmed


Binary Codes
Digital systems represent and manipulate not only binary
numbers, but also many other discrete elements of
information
Any discrete element of information that is distinct among a
group of quantities can be represented with a binary code
(i.e., a pattern of 0s and 1s)
An nbit binary code is a group of n-bits that assumes up to 2 n
distinct combinations of 1s and 0s, with each combination
representing one element of the set that is being coded
The bit combination of an nbit code is determined from the
count in binary from 0 to 2n 1
Each element must be assigned a unique binary bit
combination, and no two elements can have the same value;
otherwise, the code assignment will be ambiguous.

43 Digital Logic Design by Dr. Ashfaq Ahmed


Binary-Coded Decimal (BCD)
Numbers
Although binary numbers are very
commonly used in digital systems, but still
few people are more comfortable with
decimal numbers
As the machines are operated on binary
numbers, the solution is to get the decimal
numbers, convert them into binary one and
after all operations, the binary numbers
should be converted back to decimal
numbers
It means we need to store the decimal
numbers in the computers, where the
Digital Logic Design by Dr. Ashfaq Ahmed
44
decimal numbers need to be stored in 1
Binary-Coded Decimal (BCD)
Numbers (2)
A number with k decimal digits will require
4k bits in BCD
For example, Decimal 396 is represented in
BCD with 12 bits as 0011 1001 0110
If a number is between 0 and 9, its BCD
and binary representations will be the same
Example:
(185)10 = (0001 1000 0101)BCD =
(10111001)2
(10) 10 = (0001 0000)BCD = (1010)2
45
(15) = (0001 0101)
Digital Logic 10
Design by Dr. Ashfaq Ahmed BCD = (1111)2
BCD Addition
Maximum addition result of two decimal numbers
(including carry) would be 9+9+1 = 19
From above discussion it is concluded that if two
binary numbers are added the range of the result will
be from 00000~10011
If two BCD numbers are added, the range of result will
be 00000~11001, where the MSB represents the carry
and the remaining 4-bits represents the BCD sum
result
If the binary sum of two numbers is less than or equal
to 1001, the result will be a valid BCD digit
If the binary sum of two numbers is greater than
1001, the result will be an invalid BCD digit

46 Digital Logic Design by Dr. Ashfaq Ahmed


BCD Addition (2)
The most significant bit position of the
binary sum and a decimal carry differ by 16
10 = 6
The addition of 6 = (0110)2 to the binary
sum converts it to the correct BCD digit and
also produces a carry as required

47 Digital Logic Design by Dr. Ashfaq Ahmed


BCD Addition (3)
The addition of two ndigit unsigned BCD
numbers follows the same procedure as
discussed before
Example:
Consider the addition of 184 + 576 = 760
in BCD:

48 Digital Logic Design by Dr. Ashfaq Ahmed


Decimal Arithmetic
Representation of signed decimal BCD
numbers are same as that of signed binary
numbers
We either use the signed-magnitude or
signed-compliment system, but later one is
most common
The positive sign of a BCD number is
represented with 0000 (0 decimal) and the
negative sign is represented with 1001 (9
decimal)
10s compliment is most commonly used
49 10s
Digital Logiccompliment of a BCD number is found
Design by Dr. Ashfaq Ahmed
Decimal Arithmetic (2)
Addition is done by adding all digits,
including the sign digit
Assumed that all negative numbers are in
10s compliment form
Example:
(+375) + (-240) = +135

50 Digital Logic Design by Dr. Ashfaq Ahmed


Gray Code
1-bit toggling in case moving from one
number to the next one, e.g. in binary
system 7 is 0111 and 8 is 1000, which
means all four bits are toggled
In gray code, 7 is 0100 and 8 is 1100,
where only one is bit is toggled in 7 to
make it 8
The Gray code is used in applications in
which the normal sequence of binary
numbers generated by the hardware may
produce an error or ambiguity during the
transition from one number to the next
Digital Logic Design by Dr. Ashfaq Ahmed
51
Gray Code (2)
Decimal Binary Gray Decimal Binary Gray
Code Code
0 0000 0000 8 1000 1100
1 0001 0001 9 1001 1101
2 0010 0011 10 1010 1111
3 0011 0010 11 1011 1110
4 0100 0110 12 1100 1010
5 0101 0111 13 1101 1011
6 0110 0101 14 1110 1001
7 0111 0100 15 1111 1000

52 Digital Logic Design by Dr. Ashfaq Ahmed

Вам также может понравиться