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.
Discussion:
16 comments Page 2 of 2.
Sanket said:
1 decade ago
Sign can't be reverse, can be change.
Crystal said:
1 decade ago
@Sanket.
What is the difference between reversing and changing the sign?
What is the difference between reversing and changing the sign?
Ann said:
1 decade ago
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:
9 years ago
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.
Prakash said:
8 years ago
#include<stdio.h>
int main()
{
int x=1;
x=x<<31;
printf("x = %d \n",x);
}
It will change the sign of x and also changes its value.
int main()
{
int x=1;
x=x<<31;
printf("x = %d \n",x);
}
It will change the sign of x and also changes its value.
Prakash said:
8 years ago
#include<stdio.h>
int main()
{
int x=1,y;
y=x<<31;
printf("x = %d \n",x);
printf("y = %d \n",y);
}
~
~
int main()
{
int x=1,y;
y=x<<31;
printf("x = %d \n",x);
printf("y = %d \n",y);
}
~
~
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers