<< Return to Homework Page

Lab 7 : Logically Speaking

Lab Overview

Part 1

In life we're used to dealing with decimal numbers ("real" numbers as one of my friends put it) but computers only deal with 0's and 1's, which then compose a binary number system. Luckily, binary digits and decimal digits work about the same. Each digit in a decimal number represents a multiple of some power of 10. Like: 600 = 6*100 = 6*102. The rightmost decimal digit (still to the left of the decimal point) represents a multiple against 100 = 1, the next digit to the left is a multiple of 101, the next to the left is a multiple of 102, etc. (Remember, in CS we usually start counting with 0 instead of 1).

Similarly, each binary digit gives a multiple of a power of 2. So the rightmost digit is a multiple of 20 = 1, the next one to the left is a multiple of 21 = 2, etc. In the exercises below we'll practice converting between binary numbers and decimal numbers. The table below gives the decimal value of the first few powers of 2.

Power of 2Decimal ValuePower of 2Decimal Value
20127128
21228256
22429512
2382101024
24162112048
25322124096
26642138196

Question 1(A): Convert the following binary numbers into the equivalent decimal value.

Question 1(B): Convert the following decimal numbers into the equivalent binary number.

Question 1(C): Describe an algorithm that, given a binary number, could produce the equivalent decimal number. Try to make your description as close to Java code as possible, but don't worry about having perfect syntax. If necessary, you can resort to describing steps in English.











Part 2

In lecture we were introduced to the idea of using the binary digits of 0 and 1 as the boolean values false and true. For these boolean values we can also have variables - just like with the variables we used in our Java programming. When writing these variables in a logical statement these variables are combined using the operators logical AND (*), logical OR (+), and logical NOT (! or a bar over the negated statement).

For a given logical variable A there are two different ways it can be written: A or A. The first statement is true if the variable A holds the value of 1 (used to represent true). The second statement is negated, so it is true if the variable A holds the value of 0 (used to represent false).

Question 2(A): Given the following values for the given variables, determine if the statements below resolve to true or to false.

A = 1, B = 1, C = 0, D = 0

Part 3

Truth tables are a useful tool when working with boolean expressions. A truth table says, given any possible input, what the resulting output should be. Here's an example expression and its equivalent truth table. Expression: A*!B + !A*B

Input AInput BOutput
0 0 0
0 1 1
1 0 1
1 1 0

Question 3(A): For the boolean expressions below, write out a truth table showing outputs equivalent to what the expression gives.

Remember also that we can also express these boolean statements as circuits using the AND gate, OR gate, and the NOT gate. Here are all of the gates pictured below.

Question 3(B): For each of the given truth tables below, draw a circuit using AND, OR, and NOT gates to represent it. A good way to go about doing this is by using the OR'ing of AND's technique. First, design a separate circuit for each input case where the the circuit should return true. Each of these circuits should be designed to return true only when it's specific case somes up (using AND gates). Next, combine the outputs of all of those truth circuits using OR gates. In this way you have one large circuit that returns true whenever the truth table does.

  1. Input AInput BInput COutput
    0 0 00
    0 0 11
    0 1 00
    0 1 10
    1 0 00
    1 0 10
    1 1 00
    1 1 11





  2. Input AInput BInput COutput
    0 0 00
    0 0 10
    0 1 00
    0 1 11
    1 0 00
    1 0 11
    1 1 00
    1 1 11





Part 4

Finally, we can find that, while the OR'ing of AND's technique is quite useful and a great starting point, we can often simplify the expressions it gives. Here a few simple resolution rules.

    Commutative Laws
  1. A + B = B + A
  2. A*B = B*A
  3. Associative Laws
  4. (A + B) + C = A + (B + C)
  5. (A*B)*C = A*(B*C)
  6. Distributive Laws
  7. A*(B+C) = A*B + A*C
  8. A + (B*C) = (A+B)*(A+C)
  9. Identity Laws
  10. A + A = A
  11. A*A = A
  12. Resolution Laws
  13. A*B + A*B = A
  14. (A + B)*(A+B) = A
  15. Redundance Laws
  16. A + A*B = A
  17. A*(A+B) = A
  18. 1/0 Identity Laws
  19. 0 + A = A
  20. 0 * A = 0
  21. 1 + A = 1
  22. 1*A = A
  23. Inverse Laws
  24. A + A = 1
  25. A*A = 0
  26. De Morgan's Laws
  27. (A + B) = A * B
  28. (A * B) = A + B

The last two rule are known as De Morgan's laws, which were invented by the mathematician Augustus De Morgan.

Question 4: Use the rules above to simply the boolean expressions below. (The only logical variables involved are A, B, C, and D. If any of the 4 variables are missing from the expression, you can treat the expression as if the missing variable did not exist.) Note that you could write a truth table for the initial expression, and for your final expression if you wanted to be certain that both statements were equivalent.