Advertisement
Guest User

Untitled

a guest
May 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. template<typename _Type>
  2. _Type swap(_Type variable)
  3. {
  4.     const size_t _Type_size = sizeof(_Type);
  5.     const size_t swaps_count = _Type_size >> 1;
  6.  
  7.     _Type swapped_variable = 0;
  8.     size_t swap_distance = _Type_size - 1;
  9.  
  10.     for (size_t index = 0; index < swaps_count; index++)
  11.     {
  12.         swapped_variable |= (variable >> (swap_distance << 3)) & (0xFF << (index << 3));
  13.         swapped_variable |= (variable << (swap_distance << 3)) & (0xFF << ((index+swap_distance) << 3));
  14.         swap_distance -= 2;
  15.     }
  16.  
  17.     return swapped_variable;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement