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.
Printable View
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.
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
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.
Ok thanks