#### Archived

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

# 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.

## 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 on other sites
Hmmm, I think it will work.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
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 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 on other sites
Actually I''m doing this in hardware, and another shifter would cost to much, so I want to reuse an old one that wouldn''t be being used at that moment.

LinaInverse

##### 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 on other sites
turn it upside down.
its now a left shifter

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631717
• Total Posts
3001876
×