I am trying to implement a rotate left function that rotates an integer x left by n bits
The best way is:
int rotateLeft(int x, int n)
{
_asm
{
mov eax, dword ptr [x]
mov ecx, dword ptr [n]
rol eax, cl
}
}
If you need to rotate an int variable right in your code, then the fastest way is:
#define rotl( val, shift ) _asm mov eax, dword ptr[val] _asm mov ecx, dword ptr [shift] _asm rol eax, cl _asm mov dword ptr [val], eax
val is the value you rotate, shift is the length of the rotation.