Export (0) Print
Expand All
div
eof
Expand Minimize

_swab

Swaps bytes.

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

src

Data to be copied and swapped.

dest

Storage location for swapped data.

n

Number of bytes to be copied and swapped.

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.

Routine

Required header

_swab

<stdlib.h>

For additional compatibility information, see Compatibility in the Introduction.

// 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

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

Community Additions

ADD
Show:
© 2014 Microsoft