-
Jul 23rd, 2006, 09:24 AM
#1
Thread Starter
Addicted Member
rol & ror
Is there a way of rotating bits in C?
e.g. in asm,
rol eax, 4
ror eax, 3 etc.
I know i could use inline asm, but i was wondering if there was a C equiv
Cheers.
-
Jul 23rd, 2006, 09:40 AM
#2
Re: rol & ror
i am not sure though, forgot the working of rol and ror, but maybe '<<' and '>>' operators could do this.
Code:
int num = 1;
num = num << 1; //will give you 2
num = num << 2; //will give you 8
num = num >> 1; //will give you 4
Last edited by Harsh Gupta; Jul 23rd, 2006 at 09:52 AM.
-
Jul 23rd, 2006, 05:38 PM
#3
Re: rol & ror
There are no operators for rotation in C++, you will have to work with shifts (<< and >>). A left rotate by x can be written, assuming 32 bit integers, as (a << x | a >> 32-x).
Maybe the compiler is smart enought to optimize this into a rotate instruction.
-
Jul 24th, 2006, 12:28 AM
#4
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|