Bitwise Shift

I understand how bitwise shift operators work. But in book, it appears that they work differently for signed and unsigned integral types. Specifically, the book says the following:

"Right shifting an unsigned quantity always fits the vacated bits with zero. Right shifting a signed quantity will fill with bit signs (`arithmetic shift') on some machines and with 0-bits (`logical shift') on others."

I don't understand what it means "fill with bit signs (arithmetic shift)". What is arithmetic shift?
Last edited on
arithmetic shift is one that follows the arithmetic definition of right shift: it performs division by 2n. So, right-shifting the 8-bit value 11111110 (-2 in 2's complement) by 1 gives you 11111111 (-1 in 2's complement)

logical shift is the one that operates on the bits, with no regard for how the bit pattern forms the value, and right-shifting the 8-bit value 11111110 (-2 in 2's complement) gives you 01111111 (+127)
Topic archived. No new replies allowed.