[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Rotate accumulator right using bitwise operators?

Posted on 1999-11-20
2
Medium Priority
?
620 Views
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,
arut
0
Comment
Question by:arut
2 Comments
 
LVL 33

Expert Comment

by:hongjun
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.

hongjun
0
 
LVL 5

Accepted Solution

by:
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

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