0% found this document useful (0 votes)
23 views160 pages

Lec01 CSE345

Uploaded by

2022-1-60-086
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views160 pages

Lec01 CSE345

Uploaded by

2022-1-60-086
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 160

Lec.

01
CSE 245
Prepared by msj
CSE-345

• Course Code: CSE-245


• Title: Synthesis and Optimization of Logic Circuits
• Instructor: Dr. Md Sawkat Ali
• Credit: 4
Syllabus
• Digital logic and integrated circuits.
• Design process and technology styles.
• Prerequisites review: Combinational and sequential circuit design.
• Data-path circuit design and optimization using polynomial algebra.
• Basic theory: set and graph concepts.
• Timing analysis and functional simulation.
• Formal verification
• Boolean algebras. Relations. Lattices. Algebra of Boolean functions.
• Cofactors. Boole/Shannon theorem. Binary decision diagrams (BDDs).
• Two-level optimization. Cube representation. Unate functions.
• Multilevel optimization. Algebraic division methods.
• Finite-state machines and sequential circuit optimization., Contemporary topics.
Course Objectives
The main objectives of the course are to facilitate you to achieve the highest
level Learning Taxonomy so that at you, the end of the course, will be able
to-

• Know what the digital systems are, how they differ from analog systems
and why it is advantageous to use the digital systems in many applications.
• Comprehend different number systems including the binary system and
Boolean algebraic principles
• Apply Boolean algebra to switching logic design and simplification.
• Analyze a given digital system and decompose it into logical blocks
involving both combinational and sequential circuit elements.
• Synthesize a given system starting with problem requirements, identifying
and designing the building blocks, and then integrating blocks designed
earlier
• Validate the system functionality and evaluate the relative merits of
different designs.
• Optimization of the existing design and perform new research.
Reference Book

• Text-1:
– G. D. Micheli. Synthesis
and Optimization of Digital
Circuits, 1st edition,
McGraw. Hill
Reference Book

• Ref-1:
Hachtel, Gary D.,
and Fabio Somenzi.
Logic Synthesis and
Verification
Algorithms, 1st ed.
Boston, MA.: Springer.
Reference Book

• Ref-2:
Md. Mozammel Huq
Azad Khan, Digital
Logic Design,
Bangladesh University
Grants Commission,
Dhaka, Bangladesh.
Reference Book

• Ref-3:
Ronald J. Tocci, Neal
Widmer, Greg Moss,
Digital Systems:
Principles and
Applications, 11th
edition, Pearson.
Course Website
– http://bit.ly/ewucseALI
– You will find
• Syllabus
• Course lecture
• Lab Manual
• PDF documents
Introduction
Digital Logic Design- What is it?
The Three Terms
Digital:
Logic:
Design:

Synthesis and Optimization of Logic Circuit: What is it?


Another Three Terms
Synthesis
Optimization
Logic Circuit
Analysis versus Design
• Analysis
– a process of determining the behavior of a
given system / circuit
• Design / Synthesis
– a process of going from a formal description /
technical specifications to be met to a system /
circuit diagram
Analysis: Given a system /circuit,
find y = f (x)

input Digital Circuit output


X
f y

note: a unique process


Design: Given a specification /
behavior of y, design / build
system / circuit f (x)

input Digital Circuit output


X
f y

note : not a unique process


Digital computers & information
1. Information is represented by physical
quantities called signals

2. Electrical signals: voltage, current

3. The signals use two discrete values /


ranges and are therefore said to be binary
Digital versus Analog
• Digital systems have inputs and outputs
that are represented by discrete values

+5 x y

0
time

Binary digital systems have exactly two possible input /


output values, i.e., 0 or +5 V.
Digital versus Analog
• Analog systems have inputs and outputs
that take on a continuous range of values

+5

0
time
Pros & cons of digital vs analog
• Digital systems have inherent ability to deal
with electrical signals that have been
degraded by transmission through circuits

• The real world operates in an analog


fashion-that is continuously;
– thus digital systems need interface devices
( sensor, actuators, converters ) to control
analog devices
Digital vs. analog
• Convenient to think of digital systems as having only
discrete, digital, input/output values
• In reality, real electronic components exhibit
continuous, analog, behavior

• Why do we make the digital abstraction anyway?


– switches operate this way
– easier to think about a small number of discrete values
• Why does it work?
– does not propagate small errors in values
– always resets to 0 or 1
Advantages of Digital
Techniques
1. Easy storage of information
2. Accuracy and precision
3. Easier to design
4. Programmability
5. Less affected by noise
6. Easier fabrication processes
Number Systems
Common 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
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
Conversion Among Bases
• The possibilities:

Decimal Octal

Binary Hexadecimal
Quick Example

2510 = 110012 = 318 = 1916

Base
Decimal to Decimal (just for fun)

Decimal Octal

Binary Hexadecimal
Weight as
12510  100+25  100+20+5
power
=>12510 = 5 + 20 + 100
12510 => 5 x 100 = 5
2 x 101 = 20
1 x 102 = 100
125
Base
Binary to Decimal

Decimal Octal

Binary Hexadecimal
Binary to Decimal
• Technique
– Multiply each bit by 2n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 =
2
0 x 22 =
0
1 x 23 =
8
0 x 24 =
0
1 x 25 =
32
Octal to Decimal

Decimal Octal

Binary Hexadecimal
Octal to Decimal
• Technique
– Multiply each bit by 8n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the
“weight” of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary

Decimal Octal

Binary Hexadecimal
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant
bit)
– Second remainder is bit 1
– Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1 Reverse Order
2 3 1
1 1

12510 = 11111012
Octal to Binary

Decimal Octal

Binary Hexadecimal
Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent
binary representation
Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Decimal to Octal

Decimal Octal

Binary Hexadecimal
Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder
Example
123410 = ?8

8 1234
8 154 2
8 19 2 Reverse Order
2 3

123410 = 23228
Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Example
123410 = ?16

16 1234
16 77 2
Reverse Order
16 4 13 = D
0 4

123410 = 4D216
Binary to Octal

Decimal Octal

Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278
Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Octal to Hexadecimal
• Technique
– Use binary as an intermediary
Example
10768 = ?16

1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF
Exercise – Convert …
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF

Answer
Fractions
• Decimal to decimal (just for fun)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14
Fractions
• Binary to decimal

10.1011 => 1 x 2-4 = 0.0625


1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions Now
Actual Order
• Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
Exercise – Convert ...

Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Exercise – Convert ...

Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82

Answer
Questions or Suggestions
10 Minutes
Binary Math
Decimal Addition Example
1) Add 8 + 7 = 15
Add 3758 to 4657: Write down 5, carry 1

2) Add 5 + 5 + 1 = 11
111 Write down 1, carry 1
3758 3) Add 7 + 6 + 1 = 14
+ 4657 Write down 4, carry 1

8 415 4) Add 3 + 4 + 1 = 8
Write down 8
Decimal Addition Explanation

What just happened?


111
3758 1 1 1 (carry)
3 7 5 8
+4 6 5 7
+ 4657 -
8 14 11 15 (sum)
10 10 10 (subtract the base)

8 4 1 5

So when8the
41 5 of a column is equal to or greater than
sum
the base, we subtract the base from the sum, record the
difference, and carry one to the next column to the left.
Binary Addition Rules

Rules:
–0+0 =0
–0+1 =1
–1+0 =1 (just like in decimal)

 1+1 = 210
= 102 = 0 with 1 to carry

 1+1+1 = 310
= 112 = 1 with 1 to carry
Binary Addition Example 1

Col 1) Add 1 + 0 = 1
Example 1: Add Write 1
binary 110111 to 11100 Col 2) Add 1 + 0 = 1
Write 1
Col 3) Add 1 + 1 = 2 (10 in binary)
1 1 1 1 Write 0, carry 1
1 1 0 1 1 1 Col 4) Add 1+ 0 + 1 = 2
Write 0, carry 1
+ 0 1 1 1 0 0 Col 5) Add 1 + 1 + 1 = 3 (11 in binary)
Write 1, carry 1
1 0 1 0 0 1 1
Col 6) Add 1 + 1 + 0 = 2
Write 0, carry 1
Col 7) Bring down the carried 1
Write 1
Binary Addition Explanation

In the first two columns,


What is actually there were no carries.
happened when we In column 3, we add 1 + 1 = 2
carried in binary? Since 2 is equal to the base, subtract
the base from the sum and carry 1.
1 1 1 1 In column 4, we also subtract
the base from the sum and carry 1.
1 1 0 1 1 1
In column 5, we also subtract
+ 0 1 1 1 0 0 the base from the sum and carry 1.
2 3 2 2 In column 6, we also subtract
- 2 2 2 2 . the base from the sum and carry 1.
In column 7, we just bring down the
1 0 1 0 0 1 1 carried 1
Binary Addition Verification

You can always check your Verification


answer by converting the
figures to decimal, doing the 1101112  5510
addition, and comparing the +0111002 + 2810
answers.
8310

1 1 0 1 1 1 64 32 16 8 4 2 1
+ 0 1 1 1 0 0 1 0 1 0 0 1 1
1 0 1 0 0 1 1 = 64 + 16 + 2 +1
= 8310
Binary Addition Example 2

Example 2: Verification
Add 1111 to 111010. 1110102  5810
+0011112 + 1510
1 1 1 1 1 7310
1 1 1 0 1 0
+ 0 0 1 1 1 1 64 32 16 8 4 2 1
1 0 0 1 0 0 1
1 0 0 1 0 0 1
= 64 + 8 +1
= 7310
Decimal Subtraction
Example

Subtract 1) Try to subtract 5 – 7  can’t.


Must borrow 10 from next column.
4657 from 8025: Add the borrowed 10 to the original 5.
Then subtract 15 – 7 = 8.
2) Try to subtract 1 – 5  can’t.
7 9 11 Must borrow 10 from next column.
But next column is 0, so must go to
8 10 2 15 column after next to borrow.
- 4 6 5 7 Add the borrowed 10 to the original 0.
Now you can borrow 10 from this column.
3 3 6 8
Add the borrowed 10 to the original 1..
Then subract 11 – 5 = 6
3) Subtract 9 – 6 = 3
4) Subtract 7 – 4 = 3
Decimal Subtraction Explanation

8 0 2 5
- 4 6 5 7
3 3 6 8
 So when you cannot subtract, you borrow from the
column to the left.
 The amount borrowed is 1 base unit,
which in decimal is 10.
 The 10 is added to the original column value,
so you will be able to subtract.
Binary Subtraction
Explanation

 In binary, the base unit is 2

 So when you cannot subtract, you borrow from the


column to the left.
 The amount borrowed is 2.
 The 2 is added to the original column value, so
you will be able to subtract.
Binary Subtraction
Example 1
Col 1) Subtract 1 – 0 = 1
Example 1: Subtract Col 2) Subtract 1 – 0 = 1
Col 3) Try to subtract 0 – 1  can’t.
binary 11100 from 110011
Must borrow 2 from next column.
But next column is 0, so must go to
column after next to borrow.
2 1 Add the borrowed 2 to the 0 on the right.
0 0 2 2 Now you can borrow from this column
(leaving 1 remaining).
1 1 0 0 1 1 Add the borrowed 2 to the original 0.
Then subtract 2 – 1 = 1
- 1 1 1 0 0 Col 4) Subtract 1 – 1 = 0
subtract 0 – 1  can’t.
1 0 1 1 1 Col 5) Try toMust borrow from next column.
Add the borrowed 2 to the remaining 0.
Then subtract 2 – 1 = 1
Col 6) Remaining leading 0 can be ignored.
Binary Subtraction
Verification
Subtract binary
Verification
11100 from 110011: 1100112  5110
2 1 - 111002 - 2810
0 0 2 2 2310
1 1 0 0 1 1
- 1 1 1 0 0 64 32 16 8 4 2 1
1 0 1 1 1
1 0 1 1 1
= 16 + 4 + 2 + 1
= 2310
Binary Subtraction
Example 2
Verification
Example 2: Subtract
binary 10100 from 101001 1010012  4110
- 101002 - 2010
2110
0 2 0 2
1 0 1 0 0 1 64 32 16 8 4 2 1
- 1 0 1 0 0 1 0 1 0 1
1 0 1 0 1 = 16 + 4 + 1
= 2110
Logical Operations
Logical, Shift and Rotate
Operations

 A particular bit, or set of bits, within the byte can be set


to 1 or 0, depending on conditions encountered during
the execution of a program.
 When so used, these bits are often called "flags".
 Frequently, the programmer must manipulate these
individual bits - an activity sometimes known as "bit
twiddling".
 The logical, shift, and rotate operations provide the
means for manipulating the bits.
Logical OR Rules

OR Operations

• OR Results in 1 if either or both of the


operands are 1.

• OR Table
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
Logical OR Operation

To perform the OR operation, take one


column at a time and perform the OR
operation using the OR table.

Ex 1: 10010011
OR 0 0 0 0 1 1 1 1
1 0 0 1 1 1 1 1
Logical OR Examples

Ex 2: 11001001
OR 0 0 0 0 1 0 1 0
1 1 0 0 1 0 1 1

Ex 3: 0111
OR 0 0 1 0
0111
Logical XOR Rules

XOR Operations

• The exclusive OR. Similar to OR except that


it now gives 0 when both its operands are 1.

Rules.
0 XOR 0=0
0 XOR 1=1
1 XOR 0=1
1 XOR 1=0
Logical XOR Examples

Ex 1: 10011001
XOR 0 0 0 0 1 1 1 1

10010110
Ex 2: 0111
XOR 0 0 1 0
0101
Logical AND Rules

AND Operations

• AND yields 1 only if both its operands are 1.

Rules.
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
Logical AND Examples

Ex 1: 11010011
AND 00001111
00000011

Ex 2: 0111
AND 1 0 0 1
0001
Logical NOT

NOT Operations
• NOT is a separate operator for flipping the bits.
Rules.
NOT 0 = 1
NOT 1 = 0

Example. NOT 1 0 1 0 = 0 1 0 1
Shift and Rotate operations

Whereas logical operations allow the


changing of bit values in place,

SHIFT and ROTATE operations allow bits


to be moved left or right without
changing their values.
View
this
slide in
Fancy Shifting Animation:
a slide
show!
Multiplication
Also called left-shifting
(look at the animation)

This box is a
register

0 1 1 0 1 00 10 10
Lets
AndNow
So
AndNotice
the put
the
newthe
the
some
bits
bits
processor
emptythat
bits
shift
went
into
togets
spaces the
out
theleft
are an
register
of the
by with
filled 3 (8 zeros
bits)
registerthat
instruction
places we towon’t
are(because
dropped 8get
multiply the
because
is the 3correct
this of
rd

answer,
overflow
number
power because
of
by2)8 of overflow. If the
original number was smaller and had
three zeros on the left, then the
overflow would have only dropped
View
this
slide in
Negative Number
a slide
show!
Multiplication Overflow
For Negative numbers, be aware that
overflow will yield some strange
results

1 0 1 0 1 1 0 10
Themultiply
Let’s computer
Take thisbyerases
8-bit the
2. This bit binary
negative
means that
we left-shift by 1.
overflowed
number:and puts in =a -83
10101101 zero(or
on the right,
likepositive
it’s supposed
173) to. But the new number
is 01011010, which equals 90! This
happened because the lower limit of 8-bit
twos complement negative numbers is -
128. However, -83 * 2 would have gone
View
this Fancy Shifting Animation:
slide in
a slide Division
show!
Also called right-shifting
(look at the animation)

101 100 1 0 1 0 1 1
IfThe computer
Dividing
the Let’s
original drops
try number
dividing the
by powersbybits
was 4. that
2 is went
ofWhen
negative very
that outthen
(-85), of
theonly
the register
similar
happens, tothe
difference themultiplying.
to right.
wouldIfbe
number the
in original
Here,
that
the wecome in
register
ones
onnumber
thewill
leftwas
haveshift
side positive
our to original
instead (171),
the right bythen
ofbinary
zeros. the time
number
2 places.
This (4 our
computer
answer is in
is will
the
the-22. put
2ndregister.
Itpower zeros
should 2)on-21.75,
(10101011
of be the left.
=butThe
171 the
final answer
computer ORrounded
-85)is: 42. Notice
down again.thatJust
thisremember
isn’t a
totally
that when accurate
you round answer (it should
a negative be 42.75)
number
Because the computer dropped some bits we
Rotate Left operation

ROL
ROL (rotate left) shifts each bit one place to the left.
The original leftmost bit is shifted into the rightmost
position. No bits are lost.

Ex 1. ROL 1 1 0 1
1011

Ex 2. ROL 1100
=1001
Rotate Left – Multiple Bits

• ROL # bits means to rotate left # times

Ex 1: ROL 3 10011100
=11100100

Ex 2: ROL 2 11100110
=10011011
Rotate Right operation

ROR
ROR (rotate right) shifts each bit one place to the right.
The original rightmost bit is shifted into the leftmost
position. No bits are lost.

Ex 1. ROR 1 0 1 1
11 0 1

Ex 2. ROR 0 0 1 1
=1001
Rotate Right – Multiple Bits

• ROR # bits means to rotate right # times

Ex 1: ROR 3 10011100
=10010011

Ex 2: ROR 2 1 1 1 0 0 1 1 0
=10111001
Part 3
3-1 INTRODUCTION

Data today comes in different forms including numbers, text, audio,


image and video (Figure 3.1).

Figure 3.1 Different types of data


i
The computer industry uses the term “multimedia” to
define information that contains numbers,
text, images, audio and video.
Figure 3.3 Storage of different data types
3-2 STORING NUMBERS

A number is changed to the binary system before being stored in the


computer memory, as described in Chapter 2. However, there are still
two issues that need to be handled:

1. How to store the sign of the number.


2. How to show the decimal point.
Storing integers
Integers are whole numbers (numbers without a fractional part). For
example, 134 and −125 are integers, whereas 134.23 and −0.235 are
not. An integer can be thought of as a number in which the position of
the decimal point is fixed: the decimal point is to the right of the least
significant (rightmost) bit. For this reason, fixed-point representation is
used to store an integer, as shown in Figure 3.4. In this representation
the decimal point is assumed but not stored.
Figure 3.4 Fixed point representation of integers

i
An integer is normally stored in memory using
fixed-point representation.
Unsigned representation
An unsigned integer is an integer that can never be negative and can
take only 0 or positive values. Its range is between 0 and positive
infinity.

An input device stores an unsigned integer using the following steps:

1. The integer is changed to binary.


2. If the number of bits is less than n, 0s are added to the left.
Example 3.1
Store 7 in an 8-bit memory location using unsigned
representation.
Solution
First change the integer to binary, (111)2. Add five 0s to make a
total of eight bits, (00000111)2. The integer is stored in the
memory location. Note that the subscript 2 is used to emphasize
that the integer is binary, but the subscript is not stored in the
computer.
Example 3.2

Store 258 in a 16-bit memory location.

Solution
First change the integer to binary (100000010)2. Add seven 0s to
make a total of sixteen bits, (0000000100000010)2. The integer is
stored in the memory location.
Example 3.3
What is returned from an output device when it retrieves the bit
string 00101011 stored in memory as an unsigned integer?

Solution
Using the procedure shown in Chapter 2, the binary integer is
converted to the unsigned integer 43.
Figure 3.5 shows what happens if we try to store an integer that is
larger than 24 − 1 = 15 in a memory location that can only hold four
bits.

Figure 3.5 Overflow in unsigned integers


Sign-and-magnitude representation
In this method, the available range for unsigned integers (0 to 2 n − 1) is
divided into two equal sub-ranges. The first half represents positive
integers, the second half, negative integers.

Figure 3.6 Sign-and-magnitude representation

i
In sign-and-magnitude representation, the leftmost bit defines the
sign of the integer. If it is 0, the integer is positive. If it is 1, the
integer is negative.
Example 3.4
Store +28 in an 8-bit memory location using sign-and-magnitude
representation.

Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 0.
The 8-bit number is stored.
Example 3.5
Store -28 in an 8-bit memory location using sign-and-magnitude
representation.

Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 1.
The 8-bit number is stored.
Example 3.6
Retrieve the integer that is stored as 01001101 in sign-and-
magnitude representation.

Solution
Since the leftmost bit is 0, the sign is positive. The rest of the bits
(1001101) are changed to decimal as 77. After adding the sign,
the integer is +77.
Example 3.7
Retrieve the integer that is stored as 10100001 in sign-and-
magnitude representation.

Solution
Since the leftmost bit is 1, the sign is negative. The rest of the
bits (0100001) are changed to decimal as 33. After adding the
sign, the integer is −33.
One’s Complement Representation
One’s complement is another way to represent signed integers.

To encode a negative number, get the binary representation of its


magnitude, then COMPLEMENT each bit. Complementing each
bit means that 1’s are replaced with 0’s, 0’s are replaced with 1’s.
What is -5 in One’s Complement, 8 bits?

The magnitude 5 in 8-bits is % 0000 0101 = $ 05


Now complement each bit: % 1111 1010 = $FA

$FA is the 8-bit, one’s complement number of -5.

NOTE: positive numbers in 1’s complement are simply their


binary representation.
One’s Complement Examples
-5 = % 1111 1010 = $ FA
+5 = % 0000 0101 = $ 05
+127 = % 0111 1111 = $ 7F
-127 = % 1000 0000 = $ 80
+0 = % 0000 0000 = $ 00
-0 = % 1111 1111 = $ FF

For 8 bits, can represent the signed integers -127 to +127.


For N bits, can represent the signed integers

-(2(N-1) – 1) to + (2(N-1) – 1)
One’s Complement Comments
Still have the problem that there are two ways of
representing 0 (-0, and +0) . Mathematically speaking, no
such thing as two representations for zeros.

However, addition of K + (-K) now gives Zero!

-5 + 5 = $ FA + $ 05 = $FF = -0

Unfortunately, K + 0 = K only works if we use +0, does


not work if we use -0.
5 + (+0) = $05 + $00 = $05 = 5 (ok)
5 + (-0) = $05 + $FF = $04 = 4 (wrong)
Two’s Complement Representation
Two’s complement is another way to represent signed integers.

To encode a negative number, get the binary representation of its


magnitude, COMPLEMENT each bit, then ADD 1. (get One’s
complement, then add 1).
What is -5 in Two’s Complement, 8 bits?

The magnitude 5 in 8-bits is % 0000 0101 = $ 05


Now complement each bit: % 1111 1010 = $FA
Now add one: $FA + 1 = $FB

$FB is the 8-bit, twos complement representation of -5.

NOTE: positive numbers in 2’s complement are simply their


binary representation.
Two’s Complement Examples
-5 = % 1111 1011 = $ FB
+5 = % 0000 0101 = $ 05
+127 = % 0111 1111 = $ 7F
-127 = % 1000 0001 = $ 81
-128 = % 1000 0000 = $ 80 (note the extended range)
+0 = % 0000 0000 = $ 00
-0 = % 0000 0000 = $ 00 (only one zero)

For 8 bits, can represent the signed integers -128 to +127.


For N bits, can represent the signed integers

-2(N-1) to + 2(N-1) - 1
Note that negative range extends one more than positive range.
Two’s Complement Comments
Two’s complement is the method of choice for representing
signed integers.

It has none of the drawbacks of Signed Magnitude or One’s


Complement.

There is only one zero, and K + (-K) = 0.

-5 + 5 = $ FB + $ 05 = $00 = 0

Normal binary addition is used for adding numbers that represent


twos complement integers.
A common Question from Students
A question I get asked by students all the time is :
Given a hex number, how do I know if it is in 2’s complement or
1’s complement; is it already in 2’s complement or do I have put
it in 2’s complement, etc.?

If I write a HEX number, I will ask for a decimal representation


based on how you INTERPRET the encoding as a particular
method (i.e, either 2’s complement, 1’s complement, signed
magnitude).
A Hex or binary number BY ITSELF can represent
ANYTHING (unsigned number, signed number, character code,
etc.). You MUST HAVE additional information that tells you
what the encoding of the bits mean.
Questions or Suggestions
10 Minutes
Part: 4
Binary Codes
Binary Code
A binary code is just an assignment of
information to bit patterns.
Binary Codes
• Electronic digital systems use signals that have two
distinct values and circuit elements that have two
stable states.
• Digital systems represent and manipulate not only
binary numbers, but also many other discrete
elements of information.
• Any discrete element of information distinct among a
group of quantities can be represented by a binary
code.
• Binary codes merely change the symbols, not the
meaning of the elements of information that they
represent.
Binary Codes

• To represent a group of 2n distinct elements in a


binary code requires a minimum of n bits.
• There is no maximum number of bits that may be
used for a binary code.
Binary Codes for Decimal Numbers

• A set of n-bit string in which different bit strings


represent different numbers or other things is
called a code.
• A particular combination of n bit values is called
a code word.
• A code that uses n-bit strings need not contain 2n
valid code words.
Binary Codes for Decimal Numbers

• The usual interpretation of a binary number is as


defined according to the definition of a number in
in base-2 system.
• There are, however, alternate methods used to
encode numeric data into binary bit patterns.
Table 2-9 in the course text presents five such
codes. These are BCD, 2421, Excess-3,
Biquinary (5043210) and lastly the “1-out-of-10”
code.
Binary Codes for Decimal Numbers
Binary Codes for Decimal Numbers

• It is important to note that this table presents


binary codes and not binary numbers.
• A binary number is mathematically defined,
while a binary code is just an assignment of
numeric values to bit patterns.
Binary Codes for Decimal Numbers

• Each such assignment in table 2-9 does have


some particular property associated with it that
makes it a reasonable method of assignment.
• For example, a BCD number is just a natural
binary encoding of the decimal digits from 0 to 9
on four bits.
• Therefore a string of bits is grouped into groups
of four bits, and interpreted as a string of decimal
digits.
Binary-Coded Decimal (BCD)

• a BCD number is just a natural binary encoding


of the decimal digits from 0 to 9 on four bits.

0101 0111
59 in BCD (0 ~ 99)
because there are unused code words
87 in normal unsigned binary number (0 ~ 255)
Binary-Coded Decimal (BCD)

• Binary-Coded Decimal is a weighted code


because each decimal digit can be obtained from
its code word by assigning a fixed weight to each
code-word bit.
• The weights for the BCD bits are 8, 4, 2, and 1,
and for this reason the code is sometimes called
the 8421 code.
2421 code

• This code has the advantage that it is self-


complementing, that is, the code word for the 9s’
complement of any digit may be obtained by
complementing the individual bits of the digit’s
code word.

0010 = 2
9s’complement of 2 can be obtained by complementing
individual bits
1101 = (2+4+0+1) = 7
Excess-3 code

• This code is also self-complementing like 2421


code.
• Although this code is not weighted, it has an
arithmetic relationship with the BCD code.
• The code word for each decimal digit is the
corresponding BCD code word plus 0011 2.
0010 = 2 in BCD
+ 00112
= 0101 = 2 in excess-3
biquinary code
• This is a 7-bit code.
• The first two bits in this code indicate the range 0~4 or 5~9, and
the last five bits indicate which of the five numbers in the selected
range is represented.
0100100 = 2
1000100 = 7
• The redundant bits gave this code the error-detecting property.
• The biquinary code has the property that if any single bit is
corrupted as the result of (say) a circuit malfunction, the error can
be recognized.
• Note that for all values from 0 to 9, the biquinary encoding has
precisely two “1” bits and five “0” bits. Obviously the corruption
of any one bit will result in either one or three “1” bits and can be
detected on that basis.
1-out-of-10 code

• This code is is the sparsest encoding of decimal


digits, using 10 out of 1024 possible 10-bit code
words.
10000 00000 = 0
01000 00000 = 1
00100 00000 = 2
• The redundant bits gave this code the error-
detecting property.
Binomial Coefficients
• The number of different ways to choose m items
from a set of n items is given by a binomial
coefficient, denoted by n whose value is
n!/(m!*(n-m)!) m

16
for a 4-bit decimal code, there are different ways
10
to choose 10 out of 16 4-bit code words, and 10!
ways to assign each different choice to the 10
digits. So there are
(16!/(10!*(16-10)!))*10! Or 29059430400
different 4-bit decimal codes.
Gray Code

• Gray code is a code where only one bit changes


at a time while traversing from 0 to any decimal
number in sequence.
• This is a useful property when converting analog
values into digital values, since it eliminates the
problem of misinterpreting asynchronous changes
to bits between valid values.
Gray Code
• The encoding-disk problem can be solved by devising a digital
code in which only one bit changes between each pair of
successive code words. Such a code is called a Gray code.
Gray Code
Gray Code
Two ways to construct a Gray code with any
number of bits:
• Reflected code defined recursively
• From binary code
Gray Code
Gray code is defined recursively using the following rules:

• A 1-bit Gray code has two code words, 0 and 1.


• The first 2n code words of an (n+1)-bit Gray code equal
the code words of an n-bit Gray code, written in order
with a leading 0 appended.
• The last 2n code words of an (n+1)-bit Gray code equal
the code words of an n-bit Gray code, written in reverse
order with a leading 1 appended.
Gray Code
Gray code is defined from the binary code using the
following rules:

• The bits of an n-bit binary or Gray-code code-word are


numbered from right to left, from 0 to n-1.
• Bit i of a Gray-code code-word is 0 if bits i and i+1 of
the corresponding binary code word are the same,
else bit i is 1.
(When i+1=n, bit n of the binary code word is
considered to be 0.)
Character Codes

• Many applications of digital computers require the


handling of data not only of numbers, but also of letters.
• The most commonly used character code is ASCII (the
American Standard Code for Information Interchange).
• ASCII represents each character with a 7-bit string,
yielding a total of 128 characters.
• The code contains the uppercase and lower case
alphabet, numeral, punctuation, and various nonprinting
control characters.
ASCII Code
Other Codes

• Characters can be encoded according to variety


standards:
– Baudot code uses 5 bits; used for teletype
transmission
– ASCII (American Standard Code for Information
Interchange) code uses 7 bits; used in PCs.
– EBCDIC (Extended Binary Coded Decimal
Interchange Code) uses 8 bits; used by IBM
mainframes. It is an extension of BCD code.
– Unicode and ISO10646 use 16bits; Windows NT
supports Unicode.
Codes for detecting and correcting errors
• An error in a digital system is the corruption of data from its
correct value to some other value.
• i.e., a change of some bits from 0 to 1 or vice versa.
• During the processing or transmission of digital data a noise may
change some bits from 0 to 1 or vice versa.
• A short duration noise can affect only a single bit causes a single-
bit error.
• A long duration noise can affect two or more bits causes a multi-
bit error.
Codes for detecting and correcting errors
• Error-detecting codes normally add extra information to the data.
• In general, error-detecting codes contains redundant code.
• That is a code that uses n-bit strings need not contain 2 n valid code
words.
• An error-detecting code has the property that corrupting or
garbling a code word will likely produce a bit string that is not a
code word.
• Thus errors in a bit string can be detected by a simple rule - if it is
not a code word it contains an error.
Parity check
• One of the most common ways to achieve error detection is by
means of a parity bit.
• A parity bit is an extra bit included with a message to make the
total number of 1’s transmitted either odd or even.
• If an odd parity is adopted, the P bit is chosen such that the total
number of 1’s is odd.
Serial Line codes
Thank You!

You might also like