.TH swab() "" "" "General Function (libc)"
.PC "Swap a pair of bytes"
\fBvoid swab(\fIsrc\^\fB, \fIdest\^\fB, \fInb\^\fB) \fBchar *\fIsrc\^\fB, *\fIdest\^\fB; unsigned \fInb\^\fB;\fR
.PP
The ordering of bytes within a word differs from machine to machine.
This may cause problems when moving binary data between machines.
.B swab()
interchanges each pair of bytes in the array
.I src
that is
.I n
bytes long,
and places the result into the array
.IR dest .
The length
.I nb
should be an even number, or the last byte will not be touched.
.I src
and
.I dest
may be the same place.
.SH Example
This example prompts for an integer; it then prints the integer both
as you entered it, and as it appears with its bytes swapped.
.DM
#include <stdio.h>
.sp \n(pDu
main()
{
	int word;
.DE
.DM
	printf("Enter an integer: \en");
	scanf("%d", &word);
	printf("The word is 0x%x\en", word);
	swab(&word, &word, 2);
	printf("The word with bytes swapped is 0x%x\en", word);
}
.DE
.SH "See Also"
.Xr "byte ordering," byte_orde
.Xr "dd," dd
.Xr "canon.h," canon.h
.Xr "libc" libc
