Assignmnet 1
Assignmnet 1
XOR:
This operator compares the binary digits of two numbers and returns a new number based on the following
rules:
1. When both inputs are 0: The output is 0 because they are the same.
2. When the inputs are different (0 and 1): The output is 1 because they are not the same.
3. When both inputs are 1: The output is again 0 because they are the same.
Bit Comparison:
• 1 XOR 1 = 0
• 1 XOR 0 = 1
• 0 XOR 1 = 1
• 0 XOR 0 = 0
Output = 6
Execution:
Binary Presenatation:
a = 10 - 1010
b = 12 - 1100
Binary Representation:
12 in binary = 1100
10 in binary = 1010
-------------
0110 = Thus, the result is 0110, which is 6 in decimal.
Output = 4
Execution:
Binary Presentation:
a = -6 - 1010 (Two's complement)
b = 10 - 1010
Binary Representation:
-6 in binary (Two's complement) = 1010
10 in binary = 1010
-------------
0000 = Thus, the result is 0000, which is 4 in decimal.
When you apply the unsigned right shift operator to a binary number, the bits are shifted to the right
by a specified number of positions.
1. Shift the bits: Each bit is moved to the right by the specified number of positions.
2. Fill with zeros: Any empty bit positions on the left are filled with zeros.
3. Discard the bits that fall off: Bits that are shifted out of the rightmost end are discarded.
Explanation:
Applying >>> 2:
Step-by-Step Explanation
Since >>> always fills zero from the left, the result is 0010 (which is 2 in decimal).
Output: