2025-06-09 15:35:03 -05:00
2025-06-09 15:35:03 -05:00
2025-06-04 18:41:56 -05:00
2025-06-09 15:35:03 -05:00

Endianness Library

A modern C++ library for handling endianness conversions and byte order operations. This library provides a robust set of tools for working with different byte orders in a platform-independent manner.

Features

  • Platform-independent endianness detection
  • Byte order conversion utilities
  • Network byte order (big-endian) conversion functions
  • Support for various data types:
    • Integer types (8, 16, 32, 64-bit, signed and unsigned)
    • Floating-point types (float, double)
  • Modern C++20 implementation
  • Cross-platform support (Windows and Unix-like systems)

Requirements

  • C++20 compatible compiler
  • CMake 3.18 or higher

Building the Project

# Create a build directory
mkdir build && cd build

# Configure with CMake
cmake ..

# Build the project
cmake --build .

Usage

The library provides several key functions for endianness operations:

#include <Endianness.hpp>

// Check system endianness
bool isLittleEndian = Endianness::IsLittleEndian();
bool isBigEndian = Endianness::IsBigEndian();

// Convert between host and network byte order
uint16_t networkValue = Endianness::HostToNetworkOrder(hostValue);
uint16_t hostValue = Endianness::NetworkToHostOrder(networkValue);

// Reverse byte order
uint32_t reversed = Endianness::ReverseByteOrder(originalValue);

// Conditional byte order reversal
uint64_t conditionalReversed = Endianness::ReverseByteOrderIfLittleEndian(value);

Supported Types

The library supports the following types for byte order operations:

  • Unsigned integers: u8, u16, u32, u64
  • Signed integers: s8, s16, s32, s64
  • Floating-point: float, double

Project Structure

.
├── include/
│   └── Endianness.hpp    # Main library header
├── src/                  # Implementation files
├── main.cpp             # Test program
└── CMakeLists.txt       # Build configuration

License

This project is released into the public domain under the Unlicense. See the LICENSE file for details.

Contributing

Description
A C++ Library that provides byte-order-swapping for numerical types.
Readme 38 KiB
Release-1.1 Latest
2025-06-09 16:37:48 -04:00
Languages
C++ 92.4%
CMake 7.6%