C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Yes / No Questions (Q.No. 2)
2.
Bitwise can be used to reverse a sign of a number.
Yes
No
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
16 comments Page 2 of 2.

Ritesh Chandora said:   1 decade ago
@all.

i=~i|1;

~ and | both are bitwise operator and this thing can change the sign.

Sreejith said:   1 decade ago
Initially, even I though it will be possible.
For example, you input is i.
(~i)+1 will give you the negative of i.
But in cases where the value are of power 2, it won't give correct values.
So, according to me, the answer should be B itself.

Chaya said:   1 decade ago
Negetive numbers are reperesented according to the 2's complement method.

That's way @Wikiok is right and @Rafat is wrong.

Rahul said:   1 decade ago
Answer is wrong we can change sign.

Rafat said:   1 decade ago
I didnt understand your explanation.

Anyways i thought that the sign is decided by the MSB, so bitwise & or | can be used to easily alter the MSB and the sign can be changed... So how B is ans?

Wikiok said:   1 decade ago
Correct B answer:
-1*x = ~x+1, so even "~" is a bitwise operator, but "+1" is not. So "B" is correct.


Post your comments here:

Your comments will be displayed after verification.