Use C++ templates for some byte swapping.