[Webinar] Streamline your web hosting managementRegister Today


Rotate accumulator right using bitwise operators?

Posted on 1999-11-20
Medium Priority
Last Modified: 2008-03-10
Basically I would like to know how to get the effect of RAR using
C bitwise operators.

e.g 1101 should become 1100

Can someone please help me.

Regards &  Thanks,
Question by:arut
LVL 33

Expert Comment

ID: 2221961
What do you mean?
It's clockwise or anti-clockwise rotation?

1101 to become 1100? I assume it should be clockwise rotation right?

Please give more examples after you have read my comment so that I can help you.


Accepted Solution

scrapdog earned 150 total points
ID: 2222746
Assuming your "accumulator" contains n bits:

acc = ((acc&1)<<(n-1)) | (acc>>1);

So, if your accumulator contains 8 bits, this statement would be:

acc = ((acc&1)<<7) | (acc>>1);

If you wish to rotate your accumulator through a "carry bit":

acc = ((carry&1)<<7) | ((carry=acc)>>1);
carry=carry & 1;

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question