0% found this document useful (0 votes)
191 views33 pages

CPPC 12 Lecture Notes 1 Introduction To HDL Part 2 PDF

This document provides an introduction to hardware description language (HDL) programming and digital logic design. It defines key concepts like logic, statements, logical connectives, and truth tables. Examples are provided to illustrate how to translate between English statements and symbolic logic expressions, and how to determine logical equivalence using truth tables. DeMorgan's laws are also introduced as a way to show logical equivalences between compound expressions. The document is intended as a review of foundational topics needed for further study in HDL programming and digital circuits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views33 pages

CPPC 12 Lecture Notes 1 Introduction To HDL Part 2 PDF

This document provides an introduction to hardware description language (HDL) programming and digital logic design. It defines key concepts like logic, statements, logical connectives, and truth tables. Examples are provided to illustrate how to translate between English statements and symbolic logic expressions, and how to determine logical equivalence using truth tables. DeMorgan's laws are also introduced as a way to show logical equivalences between compound expressions. The document is intended as a review of foundational topics needed for further study in HDL programming and digital circuits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

CPPC 12 Introduction to HDL Lecture Note 1

Lecture Notes 1 Introduction to Hardware Description Language (HDL) Programming –

Part 2

Instructions: This lecture notes is a review of your programming logic & design, discrete
mathematics and logic circuits & design necessary in the succeeding topics. It has many
examples, exercises and tasks to be answer. Submit this lecture notes again when you finished
answering the examples. Extract the exercises and tasks separately, copy it to new document,
answer all the questions and save it with a filename of Lastname_Lecture_Note_1_Exercise1
(for exercise 1), Lastname_Lecture_Note_1_Exercise2 (for exercise 2) and
Lastname_Lecture_Note_1_Tasks.

Topic Content: Continuation

4. Logic Design Overview

4. Logic Design Overview

Digital logic design is a system in electrical and computer engineering that uses simple number
values to produce input and output operations. As a digital design engineer, you may assist in
developing cell phones, computers, and related personal electronic devices.

Industry Defined

Digital logic design is the basis of electronic systems, such as computers and cell phones.
Digital logic is rooted in binary code, which renders information through zeroes and ones, giving
each number in the binary code an opposite value. This system facilitates the design of
electronic circuits that convey information, including logic gates with functions that include AND,
OR, and NOT commands. The value system translates input signals into specific outputs. These
functions facilitate computing, robotics, and other electronic applications.

Logic

Logic is the systematic study of valid rules of inference, i.e. the relations that lead to the
acceptance of one proposition (the conclusion) on the basis of a set of other propositions
(premises).

Are there "rules" or "laws" that govern proper reasoning? Can we prove, mathematically, that a
particular argument is valid? To what extent can reasoning be automated?
CPPC 12 Introduction to HDL Lecture Note 1

1. Statement (proposition): a sentence that is either true or false, but not both.

Example. Determine if each of the following sentences is a statement.

a. 5 + 3 = 7
b. 21 / 7 = 3
c. Kennedy is President of the United States
d. He is a software engineer
e. Baltimore is the capital of Maryland.
f. 3 * z < 9
g. Every even integer greater than 2 is the sum of two primes
h. This sentence is false.

2. Compound Statements: a more complex statement composed of simpler


statements. The truth-value of a compound statement depends on the truth values of
the simpler component statements. The component statements in a compound
statement are often referred to as statement variables.

A compound statement usually consists of statement variables joined by logical


connectives.

3. Logical Connectives:

Not (negation)

1. Mathematical symbol: ~
2. ~p means "it is not the case that p" where p is some statement.
3. Other notations:  p , p
4. C++ notation:
5. The negation of a statement has the opposite truth-value from the statement.
If p is true, ~p is false.
6. The definition of negation is displayed in a truth table

p ~p

F T
T F

And (conjunction)

1. Mathematical symbol: 
2. p  q means “it is the case that p and q are true.”
3. C++ notation:
4. The conjunction of two statements p and q is true when and only when both p
and q are both true.
5. The definition of conjunction is displayed in a truth table
CPPC 12 Introduction to HDL Lecture Note 1

p q pq

F F
F T
T F
T T

6. Example
p: MIDN Berrios is an officer
q: MIDN Berrios is a gentleman
pq:

Or (disjunction)

1. Mathematical Symbol: 
2. Also called "inclusive or"
3. C++ notation:
4. The disjunction of two statements p  q is true if either p or q is true, or if
both p and q are true.
5. The definition of disjunction is displayed in a truth table

p q pq

6. Example
p: it is rainy
q: it is cold
p q:

Exclusive or
1. Mathematical Symbol:  , XOR
2. p  q is true if either p is true or q is true, but not both.
3. The definition of exclusive or is displayed in a truth table

p q pq
CPPC 12 Introduction to HDL Lecture Note 1

Precedence of logical connectives

Negation has higher precedence than conjunction (  ) and disjunction (  ).


Conjunction and disjunction are usually considered to have the same
precedence. Note that this differs from the C++ high-level language, in which
conjunction has a higher precedence than disjunction.

Example: ~ p  q is performed as

Parenthesis can be used to override normal precedence. Example:

It is important that we use parenthesis to avoid ambiguity

Example: Consider p  q  r. Is this (p  q)  r or p  (q  r)?

Translating English into symbolic logic statements

Example

Let p = “It is chilly” and q = “It is overcast” . Translate each of the following
compound statements into a mathematical statement using symbolic logic.

 It is not chilly but it is overcast


 It is not both chilly and overcast
 It is neither chilly nor overcast

Example

Let p = “0 < x” , q = “x < 2” and r = “x = 2”. Translate each of the following


compound statements into a mathematical statement using symbolic logic, given
that x is a particular real number.

 x  2
 0<x<2
 0<x  3

Assigning truth values to compound statements

We know the truth table for p  q and s  r. But what is the truth table for a
compound statement, such as ~(p  q)  (s  r)?

To develop the truth table for a complex statement we must consider each
combination of truth values for the component statements.

Example: Write the truth table for ~ p  q


CPPC 12 Introduction to HDL Lecture Note 1

Start by making columns for p and q, considering all possible combinations of


true and false.

p q

Now, use the definition of ~ to write a column for ~p. Then, write a column for
~ p  q using the definition of disjunction.

p q ~p ~ pq

Example Write a truth table for (p  q)  ~ (p  q)

p q

Have you seen this truth table before?

Example Write a truth table for ( p  q )  ~ r


CPPC 12 Introduction to HDL Lecture Note 1

Logical Equivalence

Two (compound) expressions are logically equivalent if and only if they have
identical truth values for all possible combinations of truth values for the sub-
expressions. If A and B are logically equivalent, we write A  B . (Another
notation for logical equivalence is  ; that is, if A and B are logically equivalent
then A  B .)

To test if A and B and logically equivalent, construct truth tables for A and B. If
the truth values of A and B match for all rows in the truth table, then A  B .

Example: Are p and ~ (~ p) logically equivalent?

p ~p ~ (~ p)

F T F
T F T

Example: Are ~  p  q and ~ p  ~q logically equivalent?

p q pq ~  p  q ~p ~q ~pq

F F F T T T T
F T F T T F F
T F F T F T F
T T T F F F F

DeMorgan’s Laws

Example. Show that ~( p  q)  ~p  ~q

Think about this equivalence. Does it make sense?


CPPC 12 Introduction to HDL Lecture Note 1

Consider the compound statement: Walter is 20 years old and he is in the


Navy.

For this to be true, it must be the case that it is true that Walter is 20 years old
and it is true that Walter is in the Navy.

Now think of the negation of this compound statement. For this to be false, one
or both of the parts of the compound statement must be false.

So, the negation of “Walter is 20 years old and he is in the Navy” is

A. We can also slow that ~( p  q )  ~p  ~q

B. DeMorgan‟s Laws ~( p q) ~p ~q

~( q) ~p ~q

C. Example: What is the negation of the statement: “It is cold or it is raining.”

Tautologies A tautology is a statement that is always true.

Example: Consider p  ~ p

p ~p p ~ p

F T T
T F T

Contradictions A contradiction is a statement that is always false.

Example: Consider p ~ p

p ~p p ~ p

F T F
T F F
CPPC 12 Introduction to HDL Lecture Note 1

Implication We want to be able to reason from a hypothesis to a conclusion.


We want to be able to say “If p is true, then q must be true.” or, more compactly

“if p, then q.”

This is written symbolically as pq. This is also called a “conditional.”

Examples: If Anne is a software engineer then Michelle is a Computer Engineer.

If x > 2 then x > 0.


If snow accumulation exceeds 50 inches then classes are canceled.

Truth table for pq.


p q pq
F F
F T
T F
T T

Suppose I tell you,


“If you have a 95 average then you will get an A.”

hypothesis conclusion

When is this sentence false?

Answer:

p q pq
F F
F T
T F
T T

If we have statements p and q, then pq is read “p implies q” and means


that pq is true.

English expressions which mean 

In addition to expressing pq as “if p then q,” the following English expressions
are also used (note that these expressions parallel the normal English meaning
of “if p then q”):

if p, q p implies q q if p q whenever p
CPPC 12 Introduction to HDL Lecture Note 1

Example. Construct a truth table for the statement p  ~ q  ~ p

Example: Show that the conditional p is logically equivalent to that statement


~ p  q. That is, show pq  ~ p  q

Example. Prove that ~( pq ) is logically equivalent to p  ~q.

(Do on your own!)

The contrapositive: The contrapositive of pq is ~ q ~ p.

A conditional statement is logically equivalent to its contrapositive.

Examples: Write each of the following in its equivalent contrapositive form.

 If today is Wednesday then tomorrow is Thursday.


 If the temperature goes up then it will be hotter.
 If today is Friday then I have a quiz today
CPPC 12 Introduction to HDL Lecture Note 1

Suppose we have the conditional p  q. The contrapositive is ~ q ~ p which, in


English, is

Think about this sentence. It says if q does not occur, then p does not occur. This
means that p can only occur if q occurs. Or, to put it more succinctly:

To summarize, the following are all equivalent:

 if p then q
 if p, q
 q if p
 q whenever p
 p implies q
 p q
 if not q then not p
 ~ q ~ p
 p only if q

Example

Let a = “You can access the Internet from Steve Hall”


c = “You are a computer engineering”
f = “You are a plebe”

Translate the following English sentence to a logical expression:

Exercises

Question 1. Consider the sentence: Edgar will get an A only if he hands in all his homework.

(a) Express this as if A then B.


(b) What would be an alternative equivalent way to express this?
(c) Is this a third way to express the original sentence? If Edgar handed in all his
homework, then he received an A.
(d) Express the original sentence as Blah is a necessary condition for Bleh.
(e) Express the original sentence as Blah is a sufficient condition for Bleh.
(f) Given the original sentence, can I conclude that Edgar having handed in all his
homework is a sufficient condition for his having received an A?
CPPC 12 Introduction to HDL Lecture Note 1

Question 2. Consider the sentence: If Allan is a software engineer at the PMAP, then he is not
married.

(a) Express this as Blah is a necessary condition for Bleh.


(b) Is this correct: Being a software engineer at PMAP is a necessary condition for Allan
to be unmarried.
(c) Express the original sentence as Blah is a sufficient condition for Bleh.
(d) From the original sentence, is it correct to conclude: Being unmarried is a sufficient
condition for me to conclude that Allan is a PMAP software engineer.
(e) Express the original sentence as p only if q.

Question 3. Consider the sentence:

The fact that Joshua lives in Steve Hall is a sufficient condition for me to conclude that
he is a software engineer.

(a) Convert this statement to if p then q:


(b) Express this as Blah is a necessary condition for Bleh.
(c) From the original sentence, is it correct to conclude that living in Steve Hall is a
necessary condition for being a software engineer?
(d) Express the original sentence as p only if q.

Question 4. Consider the sentence:

Justin being a senior is a necessary condition for him to be manager.

(a) Convert this statement to if p then q:


(b) Convert this statement to an alternative form of if p then q:
(c) Express the original sentence as Blah is a sufficient condition for Bleh.

Question 5. What is the truth value of this statement: If 2 + 2 = 5 then Mario is a deity.

Question 6. What is the negation of the following statement: If Jonathan is a senior then she is
cynical.

Question 7. Suppose p and q are statements and p → q is known to be false. What is the value
of p  q?

Question 8. What is the negation of the following statement:

If n is prime then n is odd or n is two.

Question 9. What is the negation of the statement “ x < 5 or x is odd” ?


CPPC 12 Introduction to HDL Lecture Note 1

The converse: The converse of p → q is q → p.

In other words, the converse of if p then q is if q then p.

The converse of a statement is not logically equivalent to the statement. If a


conditional statement is true, its converse may or may not be true.

Examples: What is the converse of the following statements?

 If today is Wednesday then tomorrow is Thursday.


 If today is Labor Day, then today is a holiday.
 If I can run 2 miles, then I can run 1 mile.
 If I turned on the light switch, then the light came on.

The inverse: The inverse of p  q is ~ p  ~ q.

In other words, the inverse of if p then q is if ~p then ~q.

The inverse of a statement is not logically equivalent to the statement. If a


conditional statement is true, its inverse may or may not be true.

Examples. What is the inverse of the statements in the last example?



Answer the following three True/False questions.

i) A conditional statement and its converse are logically equivalent.


ii) A conditional statement and its inverse are logically equivalent.
iii) The converse and the inverse of a conditional statement are logically
equivalent to each other.

Example. For each of the following statements, write the contrapositive,


converse and inverse

 If he is an Ensign, then he is a naval officer.

Contrapositive:
Converse:
Inverse:

 If n is divisible by 10, then n is divisible by 5 and n is divisible by 2

Contrapositive: If n is not divisible by 5 or n is not divisible by 2, then n is


not divisible by 10.
CPPC 12 Introduction to HDL Lecture Note 1

Converse: If n is divisible by 5 and n is divisible by 2 then n is divisible by


10.

Inverse: If n is not divisible by 10 then n is not divisible by 5 or n is not


divisible by 2.

The biconditional

Given two statements p and q, the biconditional p ↔ q, read “p if and only if q,” is the
statement that is true if p and q have the same truth values and is false if p and q have
opposite truth values.

p q p↔q

Thus, the statement “p if and only if q” is really saying two things:


So saying “p if and only q” is saying: or,


symbolically

Again, p ↔ q is logically equivalent to the conjunction of p  q and q  p. But


we already said that p  q is equivalent to the statement that

Similarly, we said that q  p is equivalent to the statement

Taking the conjunction of these two statement we have p ↔ q is equivalent to


saying

The following is an example of a biconditional: An integer is even if and only if it


is divisible by 2.

To summarize, the following are all equivalent


 p↔q
 (pq )  (q p)
 p is a necessary and sufficient condition for q
 p if and only if q

Example: Express the statement “I am happy if and only if I have found true
love” as the conjunction of two if-then statements.

Notation. From now on, we will very often abbreviate “if and only if” as iff.
CPPC 12 Introduction to HDL Lecture Note 1

Logic Gates Consider the circuit below which has 2 switches in series:

S1 S2

L Light

When will the light turn on?

We can represent the light's operation using a table:

S1 S2 Light
open open off
open shut off
shut open off
shut shut on

Change the words open and off to F and the words shut and on to T and the table becomes

S1 S2 Light This is the truth table for the  logical connective.


F F F We can say that the circuit above corresponds
F T F to S1  S2.
T F F
T T T

Now consider the circuit that has 2 switches in parallel.


S1

S2 L Light

When will the light turn on?

We can represent the light's operation using a table


S1 S2 Light
open open off
open shut on
shut open on
shut shut on
CPPC 12 Introduction to HDL Lecture Note 1

Changing the words open and off to F and the words shut and on to T and the table becomes

S1 S2 Light
F F F
F T T This is the truth table for the  logical connective.
T F T We can say that the circuit above corresponds to S1  S2.
T T T

Notes:

 Usually, when designing circuits, the symbol 0 is used to denote F and the symbol 1
is used to denote T.
 A compound expression as we are using it here (in the context of logic circuits) is
called a Boolean expression. We will develop a more formal definition of a Boolean
expression later in the course.

To a Computer Engineer, the computer‟s hardware is comprised of digital logic circuits.


Digital logic circuits are built from just a handful of primitive elements, called logic gates,
combined in various ways.

In a digital logic circuit, only two values may be present. The values may be 5 and + 5
volts. Or the values may be 0.5 and 3.5 volts. To allow consideration of all of these
possibilities, we will say that digital logic circuits allow the presence of two logical values: 0
and 1.

So, signals in a digital logic circuit take on the values of 0 or 1. Logic gates are devices
which compute functions of these binary signals.

In this lecture we will consider three logic gates that are used to construct digital logic
circuits:

A. Not gate (inverter) - Has one input and one output. If the input, P, is 1, the output is 0.
If the input is 0, the output is 1.

Inverter or NOT gate

P ~P
0 1 Corresponds to the ~ connective
1 0
CPPC 12 Introduction to HDL Lecture Note 1

B. And gate – has two inputs and one output. If both inputs, say P and Q, are both 1 then
the output is 1. Otherwise, the output is 0.

AND gate

P Q PQ

0 0 0
0 1 0 Corresponds to the  connective
1 0 0
1 1 1

C) Or gate – has two inputs and one output. If either or both inputs, say P and Q, are 1,
the output is 1. Otherwise, the output is 0.

OR gate

P Q PQ

0 0 0
0 1 1 Corresponds to the  connective.
1 0 1
1 1 1

Combinational circuits

A combinational circuit is a digital logic circuit whose output is determined only by the current
values of the inputs (with no dependence on past input values). A combinational circuit is built
up by combining our three basic logic gates with the following provisos:

 The output of a gate may not eventually feed back to that same gate.

 The output lines from 2 different gates cannot be combined.


CPPC 12 Introduction to HDL Lecture Note 1

The following are not combinational circuits:

Example. The air conditioning plant on a ship is controlled by a logic circuit. The air
conditioner will turn on (logical “1”) if the temperature is above 80F (logical “1”). If the
motor is overheating (logical “1”), however, a signal is sent to turn the air conditioner off.
Sketch (within the box) the logic circuit to accomplish this design.

temp > 80F


air conditioner
motor overheating

Answer:

Our study of combinational circuits will involve five (very much related) tasks:

 (Task 1) Given a digital logic circuit, write the corresponding Boolean expression.

 (Task 2) Given a Boolean expression, draw a digital logic circuit that represents this
expression.

 (Task 3) Given a digital logic circuit, construct the corresponding truth table.

 (Task 4) Given a truth table, construct a digital logic circuit that implements this truth
table.

 (Task 5) Given a digital logic circuit, design a simpler digital logic circuit that performs
the equivalent function.
CPPC 12 Introduction to HDL Lecture Note 1

TASK 1: Given a digital logic circuit, write the corresponding Boolean expression.

The Boolean expression corresponding to a digital logic circuit can be determined by


evaluating the effect of the logic gates on the input expressions.

Example: Determine the Boolean expression corresponding to the digital logic circuit
shown.

Example. Write the Boolean expression for the logic circuit shown below.

p
q

Evaluating the effect of the logic gates on the input expressions, we see:
CPPC 12 Introduction to HDL Lecture Note 1

TASK 2: Given an expression, draw a digital logic circuit that represents this
expression.

The basic approach is to write the expression on the right side of the page. Draw the circuit
from right to left, by working from the outermost part of the expression.

Example: Construct a digital logic circuit that will implement the Boolean expression
(p  ~ q)  ~ p

At the highest level, we are


q ~q
 p  ~ q
p
 p  ~ q  ~ p

~p

Now, let‟s continue to deconstruct this by looking at the top term,

q ~q
 p  ~ q
p  p  ~ q  ~ p

~p

Finally,

q ~q
 p  ~ q
p
 p  ~ q  ~ p

~p
CPPC 12 Introduction to HDL Lecture Note 1

Example: Draw a digital logic circuit that represents the Boolean expression
x  (y  ~ (x  ~ z))

TASK 3: Given a digital logic circuit, construct the corresponding truth table.

There are many convenient ways to do this. We can determine the corresponding Boolean
expression (TASK 1). Or, alternatively, we can trace through the circuit for each possible
combination of input values.

Example: Construct the truth table corresponding to the circuit shown.

Substitute p = 0 and q = 0 and r = 0 and trace through the circuit gate by gate. Repeat
this for the other combinations of input values. The resulting truth table is

p q output

Example. Construct the truth table for the circuit shown below.

p
q

p q output

Have you seen this truth table before?


CPPC 12 Introduction to HDL Lecture Note 1

Example. Write the Boolean expression for the logic circuit shown below, and then
construct the truth table for it.
p
q

Evaluating the effect of the logic gates on the input expressions, we see that the output
is:

How many rows will be in this truth table?

The truth table is


p q r

Aside an aside (and not related to the example above), note that for AND gates and OR
gates, we will allow more than two inputs. For a multi-input AND gate, the output is one
if ALL of the inputs are 1. For a multi-input OR gate, the output is 1 is ANY one of the
inputs is a 1 (or if more than one input is a 1). The example below shows what we
mean.

Example. Design a digital logic circuit to implement the Boolean expression


~ A  B  ~ C  D if:
CPPC 12 Introduction to HDL Lecture Note 1

(a) You only have 2-input gates available.


(b) You have gates with any number of inputs allowed.

TASK 4: Given a truth table, construct a digital logic circuit that implements this truth
table.

Suppose the input expressions are x1 , x2 ,... x n .

a. Identify the rows of the truth table that have an output of 1.

b. For each such row, form the Boolean expression.

z1  z2  ... z n

where z i  x i if xi  1 in this row, and zi  ~ x i if x i  0 in this row.

c. After step b., we will have one Boolean expression corresponding to each row that
had an output of 1. Take the disjunction of all these Boolean expressions. The
resulting expression has the truth table under evaluation. (As an aside, an
expression such as this, which is a disjunction of several terms, where each of these
terms is a conjunction of irreducible expressions, is said to be disjunctive normal
form.)

d. Form the digital logic circuit from this Boolean expression using the technique
discussed in TASK 2 above.

Example: Construct a logic circuit for the truth table shown.

p q output

0 0 0
0 1 1
1 0 0
1 1 1

Solution:
p q output

0 0 0
0 1 1
1 0 0
1 1 1
CPPC 12 Introduction to HDL Lecture Note 1

Example: Construct a logic circuit for the truth table shown.

A B C Output

TASK 5: Given a digital logic circuit, design a simpler digital logic circuit that
performs the equivalent function.

a. Find the Boolean expression that corresponds to this logic circuit (TASK 1 above).

b. Use the Table on page 14 of the text to find a simpler logically equivalent Boolean
expression.

c. Given this simpler Boolean expression, draw the digital logic circuit that represents
this expression (TASK 2 above). This simpler circuit will perform precisely the same
way as the original (more complex) circuit.

Example. Suppose we find that a logic circuit has the Boolean expression

~ x  ~ y  ~ z  ~ x  ~ y  z 
Can this circuit be simplified?
~ x  ~ y  ~ z  ~ x  ~ y  z 

Exercises 2

Question 1 You have been tasked with designing the sprinkler system for the Commanding
Officer‟s stateroom. The CO‟s stateroom has three smoke alarms. Since the CO will be
very angry if his stateroom is drenched by a false or spurious alarm, you decide that the
sprinkler system will not be activated by any single smoke alarm. The sprinkler system will
activate if any two of the smoke alarms activate (or if all three activate).
a. Write a truth table that describes how the sprinkler operation will depend on the
status of the three smoke alarms. (Clearly state what you intend by logical 1 and
logical 0.)
b. Based on your truth table, design the digital logical circuit.
CPPC 12 Introduction to HDL Lecture Note 1

Let logical 1 mean the alarm/sprinkler is on.

Question 2 Let‟s pretend that there are four midshipman who are very good friends
(remember, this is just pretending). Their names are:

MIDN Miller
MIDN Porter
MIDN Lees
MIDN Wolz

Although they are all good friends, MIDN Lees and MIDN Wolz are youngsters, so they
“kinda-sorta” get, shall we say, “outvoted” when it comes to some decision-making.

Our four midshipmen always eat dinner together. In fact, they always eat dinner
together in one of two locations: King Hall or California Pizza Kitchen (CPK). Each day,
at 1645, they take a vote to decide where all four will eat. The voting works as follows:

 If there is a clear majority, the majority wins.


 If there is a tie vote, they all eat in King Hall with one exception: If MIDN Miller
and MIDN Porter agree on CPK, they pull rank and their choice (CPK) wins out.

Design a digital logic circuit that will allow our four midshipmen to cast their votes
electronically. Based on the votes, the logic circuit will decide (based on the rules
above) where our midshipmen will be eating dinner that day. (To make our task of
grading easier, please use the following convention: Let 1 denote a vote for CPK and 0
denote a vote for King Hall.)

Let 1 = CPK, 0 = King Hall


CPPC 12 Introduction to HDL Lecture Note 1

Number Representations

A. Decimal Integers and Decimal Notation

The decimal number system has 10 digits (0,1,2,3…9). Since it is based on 10 distinct
symbols, we say the base is 10. In decimal notation, we write a number as a string of digits.
To interpret a decimal number, we multiply each digit by the power of 10 associated with
that digit‟s position.

Example: Consider the decimal number: 6349.

This number is:


6 3 4 9

The Binary Number System

The binary number system has two digits (0 and 1). The base is two. Just as with decimal
notation, we write a number as a string of digits, but now each digit is 0 or 1. To interpret a
binary number, we multiply each digit by the power of 2 associated with that digit‟s position.

Example: Consider the binary number 1011.

This number is:


1 0 1 1 =

Converting a binary number to a decimal number

To convert a binary number to a decimal number, write the binary number as a sum of
powers of 2.

Example: Express the binary number 1011 as a decimal number.

Note: We must be careful that the base is understood. When we say “11” above, we
mean the number 11 in base 10, not the number 11 in base 2. If the base is not clear
from context, it can be made explicit by including the base as a subscript as in:
10112  1110

Example: Express the binary number 110110 as a decimal number.

Converting a decimal integer to a binary number

1. Method 1. Express the decimal number as a sum of powers of 2. To do this:


i. find the highest power of two less than or equal to the decimal
number. The binary representation will have a one in this position.
CPPC 12 Introduction to HDL Lecture Note 1

ii. Now subtract this power of two from the original decimal number.
iii. If this new decimal number is zero, we‟re done. Otherwise return to
step i. above.

Example: Convert the decimal number 78 to binary.

Think to yourself: Self, what is the largest power of 2 that is less than or equal to
78.

25  32 is a power of 2 that is less than 78, but is it the largest?

So, the binary representation of 78 will have a one in the 26  64 position:

_____ _____ _____ _____ _____ _____


_____
26  64 25  32 24  16 23  8 22  4 21  2
20  1

Now, subtracting 64 from our number 78 gives 78  64  14 . Thus, 14 is now the


number we are working with.

What is the largest power of 2 that is less than or equal to 14?

_____ _____ _____ _____ _____ _____ _____


2  64
6
2  32
5
2  16
4
2 8
3
2 4
2
2 2
1
20  1

Now, subtracting 8 from our number 14 gives 14  8  6 . Thus, 6 is now the


number we are working with. What is the largest power of 2 that is less than or
equal to 6?

Answer:

_____ _____ _____ _____ _____ _____ _____


2  64
6
2  32
5
2  16
4
2 8
3
2 4
2
2 2
1
20  1

Now, subtracting 4 from our number 6 gives 6  4  2 . Thus, 2 is now the


number we are working with.

What is the largest power of 2 that is less than or equal to 2?


CPPC 12 Introduction to HDL Lecture Note 1

_____ _____ _____ _____ _____ _____ _____


2  64
6
2  32
5
2  16
4
2 8
3
2 4
2
2 2
1
20  1

Now, subtracting 2 from our number 2 gives 0, so we are done. Filling in the
zeros, we have our answer: The decimal number 78 in binary is

_____ _____ _____ _____ _____ _____ _____


2  64
6
2  32
5
2  16
4
2 8
3
2 4
2
2 2
1
20  1

Example: Convert the decimal number 201 to binary.

At the risk of insulting your intelligence, we ask that you “memorize” the binary
representations of the decimal digits 1 through 16.

2. Method 2. Repeated division by 2

i. Divide the number by 2 to obtain a quotient and remainder. (The remainder


will be 0 or 1)
ii. If the quotient is zero, we‟re done (proceed to step iii). Otherwise, go back
to step 1., treating our quotient as the number under examination.
iii. The sequence of remainders forms the binary representation of the
number.

Example: Convert the decimal number 53 to binary.

Example: Convert the decimal number 201 to binary.

Using the algorithm, your answer should match the representation shown on the
prior page.
CPPC 12 Introduction to HDL Lecture Note 1

Binary Arithmetic

1. Example Translate the decimal first grade problem 1 + 1 = 2 to binary


notation.

We see that when we add two binary ones together, we have a carry into the next
column. This idea of “carrying over to the next column” when adding binary numbers
together is analogous to carrying over when adding decimal numbers: if the result of
the addition is a number too big to be represented as a single digit in the number
system, we carry a one over to the next column.

2. Example Translate the second grade decimal problem 1 + 1 + 1 = 3 to binary


notation.

We see that when we add three binary ones together, we have a carry into the next
column.

3. Example. Perform the addition of the two binary numbers:

101101 1111
+ 1011 + 101
------------- --------

Negative Binary Numbers

3. Two‟s complement. To find the two‟s complement of a binary number, change


each 1 to a zero and each zero to a one (i.e., invert all the bits), then add one to
this.

2. Example: What is the two‟s complement of the binary number 10010010 ?

3. Negative binary numbers using two‟s complement notation. To find the


representation of a negative decimal number:
 First find the binary representation of the number without the negative
sign
 Then take the two‟s complement. The result is the representation of
the negative number.
CPPC 12 Introduction to HDL Lecture Note 1

4. Example: Express the decimal integer –13 as an eight bit binary number.

5. Example: Express the decimal integer 53 as an eight bit binary number.

6. Why is the two‟s complement notation a good representation for negative


numbers?

A binary number, added to its two‟s complement, results in zero. This is “how its
„sposed to be: a number added to its negative should give zero.

Example: 53: 00110101


-53: 11001011

7. Note that given the binary representation of a negative number in two‟s


complement notation, we can use the “inverting all the bits and adding one” idea
to find the corresponding decimal equivalent.

Example. What is the decimal equivalent of this 32-bit two‟s complement


number?

1111 1111 1111 1111 1111 1111 1111 1100

B. Storage of integers (C++)

Positive integers are stored in four bytes by converting the integer to a binary number.
The right most 31 bits are used. The left most bit is set to zero (indicating a positive
number).

Negative integers are stored in four bytes by converting the integer to a binary number in
two‟s complement notation. The right most 31 bits are used. The left most bit will be a
one.
CPPC 12 Introduction to HDL Lecture Note 1

Can you explain the output of the C++ program shown below?

#include<iostream>
using namespace std;

int main( )
{
int number = 2147483646;
cout << number << endl;

number = number + 1;
cout << number << endl;

number = number + 1;
cout << number << endl;

number = number + 1;
cout << number << endl;

number = number + 1;
cout << number << endl;

return 0;
}

Digital Logic Circuits for Addition

Question: Design a digital logic circuit that will add two single bit binary numbers.

How many inputs?

How many outputs?

What is the truth table?


CPPC 12 Introduction to HDL Lecture Note 1

What can be used to implement the carry bit?

What can be used to implement the sum bit?

The circuit is:

This circuit is called a half-adder.

Example. Adding Three Bits (Full Adder)

Design a digital logic circuit to add three bits together. Call the three inputs A, B and C.

What is the truth table?

Using the techniques you learned earlier, you can show that the Boolean expression for
the Carry bit, after some simplification, is

What would be the logic circuit for the Carry bit?


CPPC 12 Introduction to HDL Lecture Note 1

You should convince yourself that the Carry bit can be implemented by two XORs.
A
B
Carry
C

This circuit (i.e., these two circuits together) is called a full adder.
Sum

Example. Consider representing the half-adder and the full-adder as shown below:
Carry Sum
A B A B

Half adder C
Full adder

Carry Sum Carry Sum


A
Sum
Design a digital logic circuit
B that can add together 2-bit adder, i.e., an adder that will add
the bits WX to the bits YZ.
Carry
A B

Half adder

Carry Sum

Hexadecimal Representation of numbers

The hexadecimal number system has 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E


and F). The base is 16. Just as with decimal notation, we write a number as a string of
digits, but now each digit is one of the 16 possible hexadecimal digits. To interpret a
hexadecimal number, we multiply each digit by the power of 16 associated with that
digit‟s position.

Example: Consider the hexadecimal number 1A9B.

This number is:


1 A 9 B
CPPC 12 Introduction to HDL Lecture Note 1

Converting a hexadecimal number to a decimal number

To convert a hexadecimal number to a decimal number, write the hexadecimal number


as a sum of powers of 16.

Example: Express the hexadecimal number 3CB as a decimal number.

Converting a hexadecimal number to a binary number

We can convert directly from hexadecimal notation to the equivalent binary


representation by using the following procedure:

 Convert each hexadecimal digit to a four digit binary number


 Concatenate the resulting four bit binary numbers

Example: Convert the hexadecimal number 4DA9 to binary.

Example: Convert the hexadecimal number 13F to binary.

Converting a binary number to a hexadecimal number

We can convert directly from binary notation to the equivalent hexadecimal


representation by using the following procedure:

 Starting at the right, collect the bits in groups of 4


 Convert each group of 4 bits into the equivalent hexadecimal number
 Concatenate the resulting hexadecimal numbers

Example: Convert 110110101001 to hexadecimal.

You might also like