Ad

Thursday 13 June 2013

Algo#13: Cyclic right shift of bits in number

Manipulation of bits are very crucial if you can apply it properly in your computing because it is one of the fastest technique for computing.

Following is simple algorithm for finding Cyclic Right Shift of bits in given number by S bits.

Step 1: Take right S bits of number, and shift it right by R-S positions, where R is number of total bits in given number, call it Partial-1.
Step 2: Take left R-S bits of number, and shift it left by S positions, call it Partial-2.
Step 3: Do OR operation between Partial-1 and Partial-2.

Following is implementation of above algorithm in c language in one line.





Please write comments if you find anything wrong or you want to add something more related to this topic.

No comments:

Post a Comment

Write your comment here.

Ad