Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

LinaInverse2010

Shifting Values

This topic is 5386 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

If I''m only have a left shifter and I need to shift right, will this work: Reverse of Bits to shift (ie. 16-bits then bit 15 goes to bit 0, and 0 goes to 15) Shift them Reverse the output Will that be valid. I can''t see why not, but I just want to make sure. LinaInverse

Share this post


Link to post
Share on other sites
Advertisement
seems like it should work... but you are probably better off writing your own function to shift bits to the right, it can''t be that hard...

Share this post


Link to post
Share on other sites
Yeah I think just writing a plain old right-shift function would be easier than writing the "reverse bits" function (unless there is some easy way to reverse bits).

Share this post


Link to post
Share on other sites
Ok. Well, there is one potential problem with your strategy- there are two kinds of right shifts, logical shifts and arithmetic shifts. For a logical shift, the empty bits on the left are always filled with 0''s (this is the more natural way of doing it). For an arithmetic shift on a signed number, the empty bits on the left are filled with the sign bit. So, if you right shift 11111101 by 1 (I''m using 8 bit numbers for simplicity), you will get 11111110 and not 01111110. In other words, right shifting -4 by 1 will give you -2 and not 126.

So you may not even want to support arithmetic shifts, but if you do then you''ll need a little extra code.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
turn it upside down.
its now a left shifter

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!