| title |
_swab | Microsoft Docs |
| ms.custom |
|
| ms.date |
11/04/2016 |
| ms.reviewer |
|
| ms.suite |
|
| ms.technology |
|
| ms.tgt_pltfrm |
|
| ms.topic |
article |
| apiname |
|
| apilocation |
msvcrt.dll |
msvcr80.dll |
msvcr90.dll |
msvcr100.dll |
msvcr100_clr0400.dll |
msvcr110.dll |
msvcr110_clr0400.dll |
msvcr120.dll |
msvcr120_clr0400.dll |
ucrtbase.dll |
api-ms-win-crt-utility-l1-1-0.dll |
|
| apitype |
DLLExport |
| f1_keywords |
|
| dev_langs |
|
| helpviewer_keywords |
_swab function |
swapping bytes |
swab function |
bytes, swapping |
|
| ms.assetid |
017142f2-050c-4f6a-8b49-6b094f58ec94 |
| caps.latest.revision |
18 |
| author |
corob-msft |
| ms.author |
corob |
| manager |
ghogen |
| translation.priority.ht |
cs-cz |
de-de |
es-es |
fr-fr |
it-it |
ja-jp |
ko-kr |
pl-pl |
pt-br |
ru-ru |
tr-tr |
zh-cn |
zh-tw |
|
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.
The swab function does not return a value. The function sets errno to EINVAL if either the src or dest pointer is null or n is less than zero, and the invalid parameter handler is invoked, as described in Parameter Validation.
See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on this and other return codes.
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, and the final byte is not copied. The _swab function is typically used to prepare binary data for transfer to a machine that uses a different byte order.
| Routine |
Required header |
_swab |
C: <stdlib.h> C++: <cstdlib> or <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 %d bytes\n %s\n\n", from, sizeof(from), to);
_swab(from, to, sizeof(from));
printf("After: %s\n %s\n\n", from, to);
}
Before: BADCFEHGJILKNMPORQTSVUXWZY 27 bytes
...........................
After: BADCFEHGJILKNMPORQTSVUXWZY
ABCDEFGHIJKLMNOPQRSTUVWXYZ.
Buffer Manipulation