标准库具有以下std::reverse
功能:
#includevoid ReverseBytes( void *start, int size ) { char *istart = start, *iend = istart + size; std::reverse(istart, iend); }
Michael Mann.. 18
不使用STL的高性能解决方案:
void reverseBytes(void *start, int size) { unsigned char *lo = start; unsigned char *hi = start + size - 1; unsigned char swap; while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; } }
虽然问题是3岁半,但其他人可能会寻找相同的东西.这就是为什么我仍然发布这个.
标准库具有以下std::reverse
功能:
#includevoid ReverseBytes( void *start, int size ) { char *istart = start, *iend = istart + size; std::reverse(istart, iend); }
不使用STL的高性能解决方案:
void reverseBytes(void *start, int size) { unsigned char *lo = start; unsigned char *hi = start + size - 1; unsigned char swap; while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; } }
虽然问题是3岁半,但其他人可能会寻找相同的东西.这就是为什么我仍然发布这个.