LESSON 01 – BITWISE OPERATIONS
LESSON
WORK
QUESTION 1
Evaluate the
following:
a) 0011 1101 AND 0110 1100
b) 0010 1000 OR 1011 1001
c) 1001 XOR 0010
d) 1011 NOR 1001
e) 0101 NAND 0111
f) 0100 XNOR 1110
g) NOT (1001 1011)
QUESTION #2
Consider
the byte A with the value 1001 1101.
a)
What
value do you get if you do A AND 0000 0000?
Can you see a pattern between A and your answer?
b)
What
value do you get if you do A AND 1111 1111?
Can you see a pattern between A and your answer?
c)
What
value do you get if you do A OR 0000 0000? Can you see a pattern between A and your
answer?
d)
What
value do you get if you do A OR 1111 1111?
Can you see a pattern between A and your answer?
e)
What
value do you get if you do A XOR 0000 0000?
Can you see a pattern between A and your answer?
f)
What
value do you get if you do A XOR 1111 1111?
Can you see a pattern between A and your answer?
QUESTION #3
Do the
logical shifts below. Assume the number is stored in one byte.
a)
17
>> 2
b)
91
<< 3
QUESTION #4
Do the
arithmetic shifts below. Assume the number is stored in one byte and
that 2’s complement is used for negative numbers.
a)
-73
>> 2
b)
-21
<< 1
QUESTION #5
Do the
circular shifts below. Assume the number is stored in one byte of
data.
a)
0101
1011 >> 2 (give your answer in
binary)
b)
147
<< 3 (give
your answer in decimal)
QUESTION #6 (TIME
PERMITTING)
In the Java
Programming language, numbers are stored in 32 bits of data. Numbers use 2’s complement.
When doing
an arithmetic shift of -122 >> 2, Java gives the expected value of -31.
When doing
a logical shift of -122 >> 2, Java gives the answer 1 073 741 793. Can you do the steps that explain that
value?
If you
happen to be a Java programmer, you can see the code and the resulting output
here.
|