Convert the following numbers from decimal into eight-bit twos-complement notation.
-17 | 11101111 |
25 | 00011001 |
For a negative number, like -17. First express the absolute value of the number as an eight-bit binary number. It this case, 00010001. Then ones-complement the number to 11101110. And finally, add in one to obtain the twos-complement or 11101111.
Which, if any, of the following additions of four-bit twos-complement numbers result in an overflow? You really don't even have to add the entire numbers to tell.
1100 + 1100 | NO |
1000 + 1000 | YES |
0100 + 0100 | YES |
1000 + 0111 | NO |
Only in parts two and three, do you add numbers of the same sign and get a result of a different sign. You don't have to add the two numbers in part four. You can never get an overflow when adding numbers of different signs.
Draw a circuit that implements the truth table shown below. The "inputs" to the truth table are A, B, and C. The output is Z. Again, review section 3.3.4 before attempting this problem.
input | output | ||
---|---|---|---|
A | B | C | Z |
0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 |
0 | 1 | 1 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 1 | 1 |
1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 |
There are four one's in the output corresponding to the minterms: A' B' C', A B' C, A B C', and A B C. This gives the Boolean expression A' B' C' + A B' C + A B C' + A B C which can be reduced to A' B' C' + A B + A C. The circuit can be drawn from either of these two expressions.
Assume x
is a C integer variables.
Describe how you would set bits
2,4, and 10 of x
to 1 and clear bits 3, 5, and 9 to 0.
You can did this in one statement.
First, you need an expression with a one in bits 2, 4, and 10 to
OR with x
to
set these bits. Assuming big-endian ordering, the appropriate
binary number is 00000010000010100 which can be written as
the C hexadecimal constant 0x414.
Clearing bits 3, 5, and 9 requires ANDing with
the complement of the binary number
00000001000101000, or 0x228.
The appropriate C-statement is
"x
= (x
| 0x414) & ~0x228 ;".
Implement the following Boolean function using only NAND gates and inverters:
f(x, y, z) = x' y + x y' z |
f(x, y, z) = NAND(NOT(x' y),NOT(x y' z)) because α + β = (α' β')' = NAND(NOT(α),NOT(β)) by deMorgan's law |
f(x, y, z) = NAND(NAND(x',y),NAND(x,y',z)) because NOT(α β) = NAND(α,β) |
f(x, y, z) = NAND(NAND(NOT(x,y),NAND(x,NOT(y),z)) |
Using truth tables show that the following pairs of Boolean equations are true:
Left as an exercise to the reader. The first reduction is called absorption and is extremely usful for simplifying Boolean circuit. The second relation is the law of distributivity. While in "normal" algebra, multiplication distributes over additions; in Boolean algebra, AND distributes over OR and OR distributes over AND.