The midterm exam will be broken into two components:
The written portion will require you to:
The review below, in addition to everything you wrote for your labs, is intended to be comprehensive. All topics which could potentially be on the exam are somehow covered by this review.
31
N
two positions to the left is equivalent to multipling N
by what (in decimal)?
4 (each shift to the left is another multiplication by two, so 22
)
N
four positions to the right is equivalent to performing truncating division (ignoring the remainder)
by what (in decimal)?
16 (each shift to the right is another division by two, so 24
)
Bit 0 (the rightmost bit)
-8
in twos complement representation?
Represent your solution using 8 bits.
8 in binary: 0000 1000 flip bits: 1111 0111 add 1: 1111 1000 1111 1000
1 + 1
with a carry-in bit set?
1 1 + 1 --- 1 with carry-out set
1 + 1
without a carry-in bit set?
0 1 + 1 --- 0 with carry-out set
1 + 0
without a carry-in bit set?
0 1 + 0 --- 1 without carry-out set
What is:
11111101 + 01000101
Specify if the result has a carry-out set and if the result sets the overflow bit.
1 11111010 11111101 + 01000101 ---------- 01000010 Carry-out set, overflow bit not set.
What is:
10010110 - 11101010
Specify if the result has a carry-out set and if the result sets the overflow bit.
10010110 - 11101010 ...is equivalent to... 10010110 + (-11101010) Original: 11101010 Flip bits: 00010101 Instead of adding 1 here, I'll set the carry-in bit for the add 0 00101111 10010110 + 00010101 ---------- 10101100 Carry-out not set, overflow bit not set.
N
.
Using only bitwise operations and bitmasks, give an expression that will produce N
, except that bit 7 is guaranteed to be one.
Express any bitmasks using 2-digit hexadecimal.
We have a binary number that looks like this: XXXX XXXX ...where X is an unknown bit. We want to produce a binary number that looks like this: 1XXX XXXX We'll need to use OR (|) for this, as OR can be forced to produce 1 as a result with an unknown number as with ((X | 1) = 1). This same reasoning gives us the bitmask to OR with. We end up with: XXXX XXXX | 1000 0000 ----------- 1XXX XXXX 1000 0000 in hexadecimal is 0x80. So overall we have: N | 0x80