【C語言】左移&右移巨集
恩...就左移與右移巨集函數
#include <stdio.h>
#define ROTATE_LEFT(NUM,BIT) ( \
(NUM<<BIT) | (NUM>>( (sizeof(unsigned)<<3)-BIT) ) \
)
#define ROTATE_RIGHT(NUM,BIT) ( \
(NUM>>BIT) | (NUM<<( (sizeof(unsigned)<<3)-BIT) ) \
)
int main() {
unsigned int x = 0xff000000 ;
printf("0x%8X\t0x%08X\n", x, ROTATE_RIGHT(x,4)) ;
printf("0x%8X\t0x%08X\n", x, ROTATE_LEFT(x,4)) ;
system("pause") ;
return 0 ;
}
沒有留言:
張貼留言