_swab (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Swaps bytes.

void _swab( char *src, char *dest, intn);

Parameters

  • src
    Data to be copied and swapped.
  • dest
    Storage location for swapped data.
  • n
    Number of bytes to be copied and swapped.

Return Values

None.

Remarks

These functions are supported by all versions of the C run-time libraries.

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.

Example

Description

The following example swaps bytes in two character strings.

Code

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

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

void main()
{
    printf( "Before:\t%s\n\t%s\n\n", from, to );
    _swab( from, to, sizeof( from ) );
    printf( "After:\t%s\n\t%s\n\n", from, to );
}
// Output
Before:   BADCFEHGJILKNMPORQTSVUXWZY
   ..........................

After:   BADCFEHGJILKNMPORQTSVUXWZY
   ABCDEFGHIJKLMNOPQRSTUVWXYZ

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stlib.h, string.h.

Link Library: coredll.dll.

See Also

htonl | htons | ntohl | ntohs

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.