Sign in to follow this  
KodeNerd

[C++] Bit-Shifting

Recommended Posts

xor    516
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
DevFred    840
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
Rockoon1    104
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

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