|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Implementation of the byte-order swap helpers. More...
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. | |
Implementation of the byte-order swap helpers.
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.
Each function reverses the byte order of its argument. On GCC/Clang the compiler built-in __builtin_bswapNN is used for optimal code generation; on other compilers a portable bit-shift fallback is provided.
| uint8_t swap_endian8 | ( | uint8_t | x | ) |
Returns the input byte unchanged (no-op for API symmetry).
* @param x Byte value to "swap". *
| uint16_t swap_endian16 | ( | uint16_t | x | ) |
Reverses the byte order of a 16-bit unsigned integer.
Algorithm:
* @param x 16-bit value to byte-swap. *
| uint32_t swap_endian32 | ( | uint32_t | x | ) |
Reverses the byte order of a 32-bit unsigned integer.
Algorithm:
* @param x 32-bit value to byte-swap. *
| uint64_t swap_endian64 | ( | uint64_t | x | ) |
Reverses the byte order of a 64-bit unsigned integer.
Algorithm:
* @param x 64-bit value to byte-swap. *
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License