Sign in to follow this  

[C++] Bit-Shifting

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It doesn't preserve it.
1010 shifted left one position: 0100

RCL and RCR (Rotate) do preserve the bit.

Share this post


Link to post
Share on other sites
Quote:
Original post by KodeNerd
I cannot remember if the bits are preserved in bit-shifting.

Bits that shift out are lost.

Quote:
Original post by KodeNerd
Example:

1010 bit-shift left
is the outcome 0100 or 0101?

It depends on the number of bits you are operating on. In a 32 bit integer, it works like this:
00000000000000000000000000001010 << 1 == 00000000000000000000000000010100

Share this post


Link to post
Share on other sites
Quote:
Original post by xor
It doesn't preserve it.
1010 shifted left one position: 0100

RCL and RCR (Rotate) do preserve the bit.



You mean ROL and ROR

RCL and RCR perform rotates too, but through the carry bit (on a 32-bit register it is a 33-bit rotation, 32+carry)

Share this post


Link to post
Share on other sites

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this