|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Byte-order swap helpers for 8-, 16-, 32-, and 64-bit unsigned integers. More...
Go to the source code of this file.
Functions | |
| uint8_t | swap_endian8 (uint8_t x) |
| Returns the input byte unchanged (no-op for API symmetry). | |
| uint16_t | swap_endian16 (uint16_t x) |
| Reverses the byte order of a 16-bit unsigned integer. | |
| uint32_t | swap_endian32 (uint32_t x) |
| Reverses the byte order of a 32-bit unsigned integer. | |
| uint64_t | swap_endian64 (uint64_t x) |
| Reverses the byte order of a 64-bit unsigned integer. | |
Byte-order swap helpers for 8-, 16-, 32-, and 64-bit unsigned integers.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Provides portable byte-swap functions used throughout the library wherever multi-byte values must be converted between host and network (big-endian) byte order. On GCC/Clang the implementations use compiler built-ins for optimal code generation; on other compilers a portable bit-shift fallback is used.
|
extern |
Returns the input byte unchanged (no-op for API symmetry).
Provided so that generic code can call swap_endianN() for any width without special-casing the single-byte case.
| x | Byte value to "swap". |
* @param x Byte value to "swap". *
|
extern |
Reverses the byte order of a 16-bit unsigned integer.
Swaps the high and low bytes. Uses __builtin_bswap16 when available for single-instruction code generation.
| x | 16-bit value to byte-swap. |
Algorithm:
* @param x 16-bit value to byte-swap. *
|
extern |
Reverses the byte order of a 32-bit unsigned integer.
Swaps all four bytes end-for-end. Uses __builtin_bswap32 when available for single-instruction code generation.
| x | 32-bit value to byte-swap. |
Algorithm:
* @param x 32-bit value to byte-swap. *
|
extern |
Reverses the byte order of a 64-bit unsigned integer.
Swaps all eight bytes end-for-end. Uses __builtin_bswap64 when available for single-instruction code generation.
| x | 64-bit value to byte-swap. |
Algorithm:
* @param x 64-bit value to byte-swap. *
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License