For unsigned numbers using a logical shift left is the same

For unsigned numbers, using a logical shift left is the same as multiplying by 2, and a logical shift right is the same as dividing by two (with a remainder). Explain why using arithmetic shift right to divide by two can be problematic for signed numbers.

Solution

Right shift of a negative signed number has implementation-defined behaviour.If your 8 bits are meant to represent a signed 8 bit value then you have a negative number. Shifting it right may fill \"empty\" bits with the original MSB (i.e. perform sign extension) or it may shift in zeroes, depending on platform and/or compiler.Hence it lead to different answer as it is compiler defined.

===============================================

Comment about work

For unsigned numbers, using a logical shift left is the same as multiplying by 2, and a logical shift right is the same as dividing by two (with a remainder). E

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site