Today ,I wrote a program for right shift of signed & unsigned int & char .Here we get some strange things.We need to understand it through program,Here is the snapshot of the program:-
Here we can see that signed char sc is different printed compare to inserted value.This is an anomaly.This is done because the the MSB is 1 But in case of signed char sc1 the printd value is same as inserted .This is because of value of MSB which is zero.In these if we take right shift of both we seen that In the case of sc the value is unchanged because if we right shift the signed char or int it right shift the all bits & MSB equal to the MSB of original value either it is zero or one.In the case of unsigned char & int it right shift all the bits & MSB becomes Zero.These changes we can easily seen in the program.In the case of si & sc there is no change in right shift because MSB is one.
No comments:
Post a Comment