0% found this document useful (0 votes)
11 views4 pages

Assignmnet 1

The document explains the bitwise XOR operator and its rules for comparing binary digits, providing examples that result in outputs of 6 and 4. It also describes the unsigned right shift operator, detailing how it shifts bits to the right while filling empty positions with zeros, with examples resulting in outputs of 1 and 2. Overall, it covers the binary representations and operations of both XOR and unsigned right shift.

Uploaded by

shravanmb163
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Assignmnet 1

The document explains the bitwise XOR operator and its rules for comparing binary digits, providing examples that result in outputs of 6 and 4. It also describes the unsigned right shift operator, detailing how it shifts bits to the right while filling empty positions with zeros, with examples resulting in outputs of 1 and 2. Overall, it covers the binary representations and operations of both XOR and unsigned right shift.

Uploaded by

shravanmb163
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignmnet 1 : XOR and Unsigned Right Shift

XOR:

The bitwise XOR operator (^).

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.

0110 (Binary) = 6 (Decimal)

The program prints 6.

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.

0000 (Binary) = 4 (Decimal)


The program prints 4.
Unsigned Right Shift:
The unsigned right shift (>>>) operator moves all bits to the right but always fills the leftmost bits with 0,
regardless of the sign.

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.

Example with Positive Decimal

Explanation:

6 in binary (4-bit representation) → 0110

Applying >>> 2:

0110 >>> 2 → 0001


Output:
1
Example with Negatuve Decimal

Step-by-Step Explanation

Convert -6 to 4-bit Two’s Complement

6 in binary (4-bit) → 0110

Take two’s complement:

0110 → Invert bits → 1001 → Add 1 → 1010

So, -6 in 4-bit binary is 1010.

Apply Unsigned Right Shift (>>> 2)

1010 >>> 2 → 0010

Since >>> always fills zero from the left, the result is 0010 (which is 2 in decimal).

Output:

You might also like