---
name: "swab"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/swab/3"
---

# swab(3)

swap adjacent bytes

## NAME

**swab** – swap adjacent bytes

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<unistd.h\>**

*void*\

**swab**(*const void \*restrict src*, *void \*restrict dest*, *ssize\_t nbytes*);

## DESCRIPTION

The function **swab**() copies *nbytes* bytes from the location referenced by *src* to the location referenced by *dest*, swapping adjacent bytes.

The argument *nbytes* should be an even number.  If *nbytes* is odd, **swab**() copies and exchanges *nbytes* -1 bytes and the disposition of the last byte is unspecified. If copying takes place between objects that overlap, the behavior is undefined. If *nbytes* is negative, **swab**() does nothing.

## SEE ALSO

[bzero(3)](/bzero/3.md), [memset(3)](/memset/3.md), [compat(5)](/compat/5.md)

## HISTORY

A **swab**() function appeared in Version 7 AT&T UNIX.
