template<typename T> T CPP_ROL(T n,constint bitN) { constint BITLEN =sizeof(T)*8; n =(n >>(BITLEN-bitN))|(n << bitN); return n; } /***************************
ROR与上面基本相同,n =(n << (BITLEN-bitN))|(n >> bitN);
*****************************/ #include<iostream> usingnamespacestd; int main() { int n = 1, bitN = 16; cout<<hex<< n <<"\n"; n = CPP_ROL(n, bitN); cout<<hex<< n; return 0; }