Is there a better way to reverse an array of bytes in memory?

后端 未结 5 2052
一向
一向 2021-01-02 00:19
typedef unsigned char Byte;

...

void ReverseBytes( void *start, int size )
{
    Byte *buffer = (Byte *)(start);

    for( int i = 0; i < size / 2; i++ ) {
             


        
5条回答
  •  天命终不由人
    2021-01-02 01:18

    The standard library has a std::reverse function:

    #include 
    void ReverseBytes( void *start, int size )
    {
        char *istart = start, *iend = istart + size;
        std::reverse(istart, iend);
    }
    

提交回复
热议问题