//将16位数字左旋转或右旋转 //original:0x2345 //rotate left 0x5234 //rotate right 0x3452 #include <iostream> using namespace std; unsigned short int rotate16Left(unsigned short int num, int n) { return (num >> n | num << (16 - n)); } unsigned short int rotate16Right(unsigned short int num, int n) { return (num << n | num >> (16 - n)); } int main() { unsigned short int num = 0x2345; printf("original:%#x ", num); printf("rotated left:%#x ", rotate16Left(num,4)); printf("rotated right:%#x ", rotate16Right(num,4)); return 0; }