Discussion :: Bitwise Operators - Yes / No Questions (Q.No.2)
Bitwise can be used to reverse a sign of a number.
Answer: Option B
No answer description available for this question.
|Wikiok said: (Apr 6, 2011)|
|Correct B answer:
-1*x = ~x+1, so even "~" is a bitwise operator, but "+1" is not. So "B" is correct.
|Rafat said: (Jun 10, 2011)|
|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?
|Rahul said: (Jul 19, 2011)|
|Answer is wrong we can change sign.|
|Chaya said: (Aug 23, 2011)|
|Negetive numbers are reperesented according to the 2's complement method.
That's way @Wikiok is right and @Rafat is wrong.
|Sreejith said: (Sep 7, 2011)|
|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.
|Ritesh Chandora said: (Aug 8, 2012)|
~ and | both are bitwise operator and this thing can change the sign.
|Mehul said: (Sep 6, 2012)|
i=~i|1; means i=~i;
take example of 2
2=0010 -2= 1110
first take complement of 2(0010) which results in 1101.
now add 1 to it resulting in 1110.
but addition is not a bitwise operator; it is arithmetic operator
|Nidhinpradeep said: (Sep 25, 2012)|
|MSB only indicates whether it is +ve or -ve. To find its complement we have to use 2's complement.|
|Mario said: (Dec 2, 2013)|
|No, Objection !
The bitwise operator can be used to reverse the sign of a certain variable.
signed char x = 5;
x = x | (1<<7) ; // here we changed the sign of x which is now -5.
//as the sign bit is the msb.
|Sanket said: (Dec 9, 2014)|
|Sign can't be reverse, can be change.|
|Crystal said: (Dec 19, 2014)|
What is the difference between reversing and changing the sign?
|Ann said: (Apr 18, 2015)|
|x=1(0001), if we set msb bit in x to high (1001 equals (-7)) it will give a negative number (means sign is changed) but not reversed (-1='1111'in binary).|
|Sheereen said: (Aug 1, 2016)|
|Actually, in some cases, it is actually possible but in most of the cases, if we try to change the sign using the bitwise operator, the number itself gets changed. Therefore, we CANNOT say that bitwise operator can be used to change the sign of the number.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.