Bit String Flicking - AP Computer Science

advertisement
Bit String Flicking
1.
Find all values of x (5 bits long) for which the following expression has a value of 00000.
(LSHIFT-1 x) AND (RCIRC-3 10111)
answer: = (lshift-1 abcde) and (11110)
bcde0 and 11101
For this to have a value of 00000, bits b, c, d, and e must all equal 0. Bit a is unconstrained. So
our answers are 10000 and 00000
2.
How many different values of X (5 bits long) will make the following equation true?
NOT 01100 OR NOT X AND 10110 = 10011
answer:
10011 or not ABCDE and 10110 = 10011
10011 or abcde and 10110 = 10011, where a = !A, b=!B, etc. (just my notation)
so, a and 1 or 1 = 1, so a =0 or 1
b and 0 or 0 = 0, so b=0 or 1
c and 1 or 0 = 0, so c=0
d and 1 or 1 = 1, so d=0 or 1
e and 0 or 1 = 1, so e=0 or 1
at this point it is not necessary to list the possibilities, just count them (i.e., 2*2*1*2*2
number of choices = 16.)
3.
List all possible values of X (5 bits long) that solve the following equation.
(LSHIFT-1 (10110 XOR (RCIRC-3 X) AND 11011)) = 01100
answer: lshift-1 (10110 xor (rcirc-3 abcde) and 11011)) = 01100
lshift-1 (10110 xor (cdeab) and 11011)) = 01100
cdeab and-ed with 11011 is cd0ab. When you XOR cd0ab with 10110 you get Cd1Ab (where the
capital letter is the opposite of it lower case). Now, if lshift-1 Cd1Ab has a value of 01100, we must have:
d=0, A=1 (hence a=0), b=0. Thus, the solution must be of the form 00x0x, where x is an “I-don’t-care”
value. The four values are 00000, 00001, 00100, and 00101.
4. evaluate: (not (lcirc-2 01100)) and (rcirc-3 (lshift-2 01110))
answer:
= (not 10001) and (rcirc-3 11000)
= 01110 and 00011
= 00010
5. find all values of x, a 5-bit long string, that make the following equation true:
(lshift-3 x) xor (rcirc-2 x) = not x
answer:
express x as abcde
(lshift-3 abcde) xor (rcirc-2 abcde) = not (abcde)
de000 xor deabc = not (abcde)
not(de000 xor deabc) = not (not(abcde))
de000 EQ deabc = abcde (where EQ means the bits must be equal)
Now, examine each bit: From d EQ d = a, we know that a=1. Similarly, b=1. The equation is now
de000 EQ de11c = 11cde. From 0 EQ 1 = c, we have c=0. From 0 EQ 1 = d, we have d=0. And finally,
from 0 EQ c = e, we have e=1.
Download