Advertisement
mgostih

Templates & Bits

Nov 17th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <typename BitVar>
  4. BitVar RotateLeft(BitVar input, unsigned char amount){
  5.     return ((input << amount) | (input >> (sizeof(input)*CHAR_BIT - amount)));
  6. }
  7.  
  8. template <typename BitVar>
  9. BitVar RotateRight(BitVar input, unsigned char amount){
  10.     return ((input >> amount) | (input << (sizeof(input)*CHAR_BIT - amount)));
  11. }
  12.  
  13. int main(){
  14.     unsigned short test = 0xABCD;
  15.     std::cout <<std::hex<< RotateLeft(test, 4) << std::endl;
  16.     system("PAUSE>NUL");
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement