---
name: "bswap"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/bswap"
---

# bswap(3)

byte swap

## NAME

bswap\_16, bswap\_32, bswap\_64 - byte swap

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <byteswap.h>
```

**uint16\_t bswap\_16(uint16\_t** *x***);** **uint32\_t bswap\_32(uint32\_t** *x***);** **uint64\_t bswap\_64(uint64\_t** *x***);**

## DESCRIPTION

These functions return a value in which the order of the bytes in their 2-, 4-, or 8-byte arguments is reversed.

## RETURN VALUE

These functions return the value of their argument with the bytes reversed.

## ERRORS

These functions always succeed.

## STANDARDS

GNU.

## EXAMPLES

The program below swaps the bytes of the 8-byte integer supplied as its command-line argument. The following shell session demonstrates the use of the program:

```
$ ./a.out 0x0123456789abcdef;
0x123456789abcdef ==> 0xefcdab8967452301
```

### Program source

```
#include <byteswap.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
    uint64_t x;
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <num>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    x = strtoull(argv[1], NULL, 0);
    printf("%#w64x ==> %#w64x\n", x, bswap_64(x));
    exit(EXIT_SUCCESS);
}
```

## SEE ALSO

[**byteorder**(3)](/byteorder/3.md), [**endian**(3)](/endian/3.md)
