[Webinar] Streamline your web hosting managementRegister Today

x
Solved

# Rotate accumulator right using bitwise operators?

Posted on 1999-11-20
Medium Priority
620 Views
Basically I would like to know how to get the effect of RAR using
C bitwise operators.

e.g 1101 should become 1100

Regards &  Thanks,
arut
0
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?

hongjun
0

LVL 5

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;
0

## Featured Post

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
Course of the Month8 days, 15 hours left to enroll