_swab
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_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

The _swab function copies n bytes from src, swaps each pair of adjacent bytes, and stores the result at dest. The integer n should be an even number to allow for swapping. _swab is typically used to prepare binary data for transfer to a machine that uses a different byte order.

Requirements

Routine Required header Compatibility
_swab <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

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 );
}

Output

Before: BADCFEHGJILKNMPORQTSVUXWZY
        ..........................

After:  BADCFEHGJILKNMPORQTSVUXWZY
        ABCDEFGHIJKLMNOPQRSTUVWXYZ

See Also

Buffer Manipulation Routines | Run-Time Routines and .NET Framework Equivalents

Show:
© 2016 Microsoft