Share via


_swab

Swaps bytes.

void _swab(
   char *src,
   char *dest,
   int n 
);

Parameters

  • src
    Data to be copied and swapped.

  • dest
    Storage location for swapped data.

  • n
    Number of bytes to be copied and swapped.

Remarks

If n is even, the _swab function copies n bytes from src, swaps each pair of adjacent bytes, and stores the result at dest. If n is odd, _swab copies and swaps the first n-1 bytes of src. _swab is typically used to prepare binary data for transfer to a machine that uses a different byte order.

Requirements

Routine

Required header

_swab

<stdlib.h>

For additional compatibility information, see Compatibility in the Introduction.

Example

// crt_swab.c

#include <stdlib.h>
#include <stdio.h>

char from[] = "BADCFEHGJILKNMPORQTSVUXWZY";
char to[] =   "..........................";

int main()
{
    printf( "Before: %s\n        %s\n\n", from, to );
    _swab( from, to, sizeof( from ) );
    printf( "After:  %s\n        %s\n\n", from, to );
}

Before: BADCFEHGJILKNMPORQTSVUXWZY .......................... After: BADCFEHGJILKNMPORQTSVUXWZY ABCDEFGHIJKLMNOPQRSTUVWXYZ

.NET Framework Equivalent

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

See Also

Reference

Buffer Manipulation