Vous êtes sur la page 1sur 6

[CSM51A F10] Homework 1 Solution

Assigned: 10/1/10 Due: 10/8/10


TAs: Pouya Dormiani (pouya@cs.ucla.edu), Jet Jiang (jetjiang@cs.ucla.edu)
October 29, 2010

Problem 1
1. The bit string 1001001100100011 is the representation of a BCD coded number. What is the hexadecimal
representation of this number?
2. Convert the radix-4 digit vector 2013212 to hexadecimal without using an intermediate binary representation.
Clearly show your steps in deriving the answer.
3. The 2421 code from Table 2.3 in the book is recreated here. Convert the radix-11 number A31 to the 2421
encoded bit string.
Table 1: The 2421 Code.
Digit Value

2421 Code

0
1
2
3
4
5
6
7
8
9

0000
0001
0010
0011
0100
1011
1100
1101
1110
1111

Solution:
1. Below are the steps in performing this conversion.
Since BCD is represented in binary as 4-bit chunks, we first group the bit string starting from the least
significant bit (LSB), to obtain the three groups,
1001, 0011, 0010, 0011
At this point some of you might have been thrown off because hexidecimal numbers also have a 4-bit
groping. You might have incorrectly assumed that the hexidecimal value was 932316 . Indeed, this
answer is wrong.
The bit string corresponds to the decimal value 932310 .
[Errata: Updated]
1

We must now convert this decimal value to binary. This is not as cumbersome as it seems. Its good to
remember that 210 = 1024.
9323 213 = 9323 8192 = 1131
1131 210 = 1131 1024 = 107
107 26 = 107 64 = 43
43 101011
i.e., 9323 10010001101011
The binary value must then be converted to hex by grouping it in chunks of 4-bits, starting with the
LSB.
10, 0100, 0110, 1011 246B16
[End Errata]
2. The key here is to recognize that 42 = 16, i.e., every two digits in the radix-4 digit vector corresponds to
one digit in the desired radix-16 result. Consequently we partition the digit vector in groups of two starting
from the least significant digit (LSD).
2, 01, 32, 12
Each radix-16 digit corresponding to a group x1 x0 can now be determined via x1 4 + x0 , consequently
2, 01, 32 , 12 21 E 616

e.g., 3 4 + 2 = 14 = E

3. The important thing to notice here is that in order to get the 2421 code we need the decimal representation of
A3111 , consequently, the radix-10 value is the intermediate representation needed to perform this conversion.
A 121 + 33 + 1 = 1244
We can just read each digit off the convertion table now to get the 2421 coded representation.
1244 0001001001000100

Problem 2
Consider two switching functions f (x1 , x0 ) and g(y1 , y0 ).
1. Write the definition of a switching function.
2. Is f (g(y1 , y0 ), x0 ) a switching function? Clarify why (limit your answer to 3 sentences).
Solution:
A switching function of n variables is the mapping from the set {0, 1}n to {0, 1}, or in mathematical notation,
f : {0, 1}n {0, 1}. A key property of this definition is that f has a mapping to the output set for every
possible permutation of its n inputs.
Let h(y1 , y0 , x0 ) = f (g(y1 , y0 ), x0 ). Since f and g are switching functions, h has a defined output for every
possible permutation of its inputs, i.e., h : {0, 1}3 {0, 1}. Therefore h is a switching function.

Problem 3
Consider the switching expression f (x, y, z) = (x0 + yz)(x + y 0 ). It is known a priori that variables x and y will
never simultaneously take on a value of 1.
p.s. a priori means prior to, i.e., in this context: known beforehand
1. What are the minterms? Use m-notation.
2. What are the maxterms? Provide both the M-notation, and conventional maxterm representation.
3. How does the a priori knowledge on x and y affect the function? Write the complete specification of f using
m-notation, taking this consequence into account.
Solution: Lets first simplify the expression and make a table. It takes too much effort to directly populate
the table with the expression in its current form, performing a little simplification can make our lives easier.
f (x, y, z) = (x0 + yz)(x + y 0 )
= x0 x + x0 y 0 + yzx + yzy 0
= x0 y 0 + yzx
Before we populate the table, lets take a quick look at the simplified expression. We can see that its in a sum
of products form, so lets leverage this to make our lives even easier. Its immediately recognizable (or will be after
some practice) that the product term xyz is m7 . Consequently we know f (1, 1, 1) = 1. The other product term x0 y 0
is missing variable z. If only it had z, we could instantly find the other min-terms. Lets force it to have variable
z. We know that x0 y 0 = x0 y 0 1, since 1 is a multiplicative identity, and therefore x0 y 0 = x0 y 0 (z + z 0 ) = x0 y 0 z + x0 y 0 z 0 .
In this manner we can instantly recognize that f (0, 0, 0) = 1 and f (0, 0, 1) = 1. We can now quickly fill the table,
without having to compute each row.
Take a few seconds to think about this approach and become comfortable with it. Which minterms correspond
to x0 ? (Hint: fix x = 0 and take all permutations of yz).
xyz

f (x, y, z)

000
001
010
011
100
101
110
111

1
1
0
0
0
0

The problem statement says that x and y can never simultaneously be 1, making f (1, 1, 0) and f (1, 1, 0)
unspecified.
P
1.
(m0 , m1 )
Q
2. (m2 , m3 , m4 , m5 ) The maxterms written in conventional form are,
x2 + x01 + x0
x2 + x01 + x00
x02 + x1 + x0
x02 + x1 + x00
3

3. The constraint makes the function incompletely


P
Pspecified. The function can be fully specified by providing
both the minterms and the dc-set, { m(0, 1),
dc(6, 7)}.

Problem 4
Simplify the switching expression f (x, y, z) = (x0 + yz) x where a b = a0 b + ab0 . Let g(x, y, z) be the simplified
switching expression. Draw the gate network for both f and g.
Solution:
f (x, y, z) = (x0 + yz) x
= (x0 + yz)0 x + (x0 + yz)x0
= x(yz)0 x + x0 + yzx0
= x(yz)0 + x0 + yzx0
= x(yz)0 + x0
= x0 + (yz)0
= (xyz)0

y
z

y
z

f(x, y, z)

f(x, y, z)
x

(a) f (x, y, z) = (x0 + yz) x

(b) f (x, y, z) = (x0 + yz) x using only


And, Or and Not

x
y
z

g(x, y, z)

(c) g(x, y, z) = (xyz)0

Problem 5
Give a high-level specification for the following function:
Input: 5 binary variables [x1 , x2 , x3 , x4 , x5 ] with xi {0, 1}.
Output: z is on (=1) if and only if there are three consecutive variables being on (=1).
(Hint: Using conditional
logical expression.)

1
if
(x

1 = 1 AND x2 = 1 AND x3 = 1 AND x4 = 0) OR

(x1 = 0 AND x2 = 1 AND x3 = 1 AND x4 = 1 AND x5 = 0) OR


Solution: z =
(x2 = 0 AND x3 = 1 AND x4 = 1 AND x5 = 1)

0 otherwise

Problem 6
Consider a set with 5 elements:
{A, B, C, D, E}
1. If we use fixed-length code to encode these elements, what is the minimum code length required for each
element?
Solution: The minimum fixed code length is 3 bits, because 23 = 8 is the minimum power of 2 which fits in
all 5 elements.
2. If we have a string of 100 elements, each element with the following occurrence, what is the average code
length for each element using the following variable-length coding scheme?

Table 2: Variable Length Code.


Element

Occurrence

Code

A
B
C
D
E

90
5
2
2
1

01
001
0001
00001
000001

Solution: The average code length for each element is:


(2 90 + 3 5 + 4 2 + 5 2 + 6 1)/100 = (180 + 15 + 8 + 10 + 6)/100 = 2.19 bits.
Note the variable-length scheme gives more compact representation per element than a fixed-length scheme.

Problem 7
Consider the switching function of 3 variables:
f (x1 , x2 , x3 ) = x1 + x2 x3 .
1. Write down the truth table representation of f .
Solution:
x1 x2 x3

000
001
010
011
100
101
110
111

0
0
0
1
1
1
1
1

2. Write down the one-set representation of f .


Solution: f (x1 , x2 , x3 ) = one-set(3, 4, 5, 6, 7).
3. f is only one instance of all switching functions of 3 variables. How many different switching functions do
we have for 3 variables? What about for 4 and 5 variables?
Solution: For 3 variables, the input domain has 23 = 8 vectors. For each switching function, it can output
a 1 or a 0 on an input vector. Thus the total number of different functions for 3 variables equals to
3
4
22 = 28 = 256. For 4 variables, this number increases to 22 = 216 = 64K = 65526, and for 5 variables, this
5
number is 22 = 232 = 4G = 4294967296.

Problem 8
Simplify the following switching expression and verify your results using truth table:
x0 + xy 0 + xyz 0 + xyzw0 .

Solution:
x0 + xy 0 + xyz 0 + xyzw0 = x0 + x(y 0 + yz 0 + yzw0 )
= x0 + (y 0 + yz 0 + yzw0 )
=

x0

x0

x0

y0

x0

y0
y0

(z 0

+ zw0 )

Table 2.6(10) Simplification

(z 0

w0 )

Table 2.6(10) Simplification

w0

y0

Table 2.6(10) Simplification

y(z 0

z0

zw0 )

Vous aimerez peut-être aussi