Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename _Type>
- _Type swap(_Type variable)
- {
- const size_t _Type_size = sizeof(_Type);
- const size_t swaps_count = _Type_size >> 1;
- _Type swapped_variable = 0;
- size_t swap_distance = _Type_size - 1;
- for (size_t index = 0; index < swaps_count; index++)
- {
- swapped_variable |= (variable >> (swap_distance << 3)) & (0xFF << (index << 3));
- swapped_variable |= (variable << (swap_distance << 3)) & (0xFF << ((index+swap_distance) << 3));
- swap_distance -= 2;
- }
- return swapped_variable;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement