#representation #binary #byte #memory

bin+lib byte-repr

A utility to inspect binary, little-endian, and big-endian memory representations of numbers

2 unstable releases

Uses new Rust 2024

0.2.0 Apr 10, 2025
0.1.0 Apr 9, 2025

#279 in Debugging

Download history 254/week @ 2025-04-08 19/week @ 2025-04-15 1/week @ 2025-04-22

274 downloads per month

MIT license

25KB
100 lines

๐ŸŽ“ Rust Crate Experiment | byte-repr

Crates.io Docs.rs Build Status MIT/Apache-2.0 licensed Downloads MSRV

A lightweight utility for inspecting and learning about memory representation of integer types in Rust.


๐Ÿ“˜ Overview

byte-repr is a simple, extensible Rust crate to help visualize how numeric types are represented in memory. It supports both little-endian and big-endian byte formats, binary representation, and hex with zero-padding.

Useful for:

  • ๐Ÿง  Learning & teaching endianness and bit-level encoding
  • ๐Ÿ› ๏ธ Debugging binary data
  • ๐Ÿงฌ Understanding low-level memory layouts in Rust

โœจ Features

  • ๐Ÿ“ฆ Print values in:
    • Binary format (grouped bits)
    • Little-endian byte array
    • Big-endian byte array
    • Hexadecimal representation (zero-padded)
  • ๐Ÿงฉ Macro-based extensibility for custom numeric types
  • ๐Ÿงช Tested against all supported integer types
  • ๐ŸŽจ Color-coded output for clarity

๐Ÿš€ Usage

Add this to your Cargo.toml:

[dependencies]
byte-repr = "0.1.0" # update after publishing

Then use in your code:

use byte_repr::represent;

fn main() {
    let x = 42u16;
    represent(&x);
}

Example Output:

example output

๐Ÿ”ง Supported Types

Currently supports:

  • i8
  • u16
  • u32
  • u64
  • u128
  • usize

โœ… impl_byterep! macro makes it easy to extend support to custom numeric types.

โš ๏ธ Limitations

  • โŒ Not yet #![no_std] compatible

  • โŒ No support for wasm32 (WebAssembly) targets

  • ๐Ÿ“Œ Relies on println! for display, which isn't available in no_std or wasm

โœ… These will be addressed in upcoming versions. Stay tuned!

๐Ÿงช Tests

Includes integration tests for:

  • Endianness checks
  • Binary and hex formatting
  • Trait conformance per type
  • Visual rendering test (smoke check)

๐Ÿ“ฆ License

See the LICENSE-MIT file for details.

๐Ÿ“‘ Changelog

See CHANGELOG.md for a history of changes.


Made with โค๏ธ by Himangshu Pan

No runtime deps