Python icon indicating copy to clipboard operation
Python copied to clipboard

Add endianness conversion algorithm

Open rodrigobnogueira opened this issue 3 weeks ago • 0 comments

Description

Added a comprehensive implementation of the endianness (byte order) conversion algorithm in Python. The implementation includes byte order swapping for 16/32/64-bit integers and bidirectional bytes ↔ integer conversions for both big-endian and little-endian formats.

Features

  • Byte order swapping: swap_endianness_16(), swap_endianness_32(), swap_endianness_64()
  • Bytes to integer conversions: bytes_to_int_little(), bytes_to_int_big()
  • Integer to bytes conversions: int_to_bytes_little(), int_to_bytes_big()
  • Comprehensive documentation with real-world use cases
  • Full doctest coverage with type hints

Use Cases

The implementation documents practical real-world applications:

  • Network protocols (TCP/IP uses big-endian/network byte order)
  • Cryptographic algorithms (MD5 uses little-endian, SHA-256 uses big-endian)
  • File format parsing (PNG, JPEG headers)
  • Binary data serialization (Protocol Buffers, MessagePack)
  • Hardware interfacing and cross-platform data exchange

References

  • https://en.wikipedia.org/wiki/Endianness
  • https://tools.ietf.org/html/rfc1700

Checklist

  • [x] I have read and followed the contributing guidelines
  • [x] This pull request is not a duplicate
  • [x] The algorithm is implemented from scratch
  • [x] The code follows the repository style
  • [x] I have read CONTRIBUTING.md
  • [x] This pull request is all my own work -- I have not plagiarized
  • [x] I know that pull requests will not be merged if they fail the automated tests
  • [x] This PR only changes one algorithm file
  • [x] All new Python files are placed inside an existing directory (conversions/)
  • [x] All filenames are in all lowercase characters with no spaces or dashes
  • [x] All functions and variable names follow Python naming conventions
  • [x] All function parameters and return values are annotated with Python type hints
  • [x] All functions have doctests that pass the automated testing
  • [x] All new algorithms include at least one URL that points to Wikipedia or another similar explanation

rodrigobnogueira avatar Dec 26 '25 13:12 rodrigobnogueira