intpack

Crates.iointpack
lib.rsintpack
version0.1.0
sourcesrc
created_at2021-09-28 00:30:40.862257
updated_at2021-09-28 00:30:40.862257
descriptionintpack is a collection of functions for packing/unpacking unsigned integers into other unsigned integers of different sizes. For example, packing 4 u8's into a u32.
homepage
repositoryhttps://github.com/Will-Banksy/intpack
max_upload_size
id457277
size7,259
Will Banks (Will-Banksy)

documentation

README

intpack

intpack is a collection of functions for packing/unpacking unsigned integers into other unsigned integers of different sizes. For example, packing 4 u8's into a u32.

!! The functions haven't been fully tested (but they should work) !!

Usage

Packing 4 u8's into a u32 using the u8_to_u32 function:

use intpack::pack;

let result = pack::u8_to_u32(&[0xff, 0x00, 0xff, 0x00]);
// Returns 0xff00ff00

And unpacking that u32:

use intpack::unpack;

let result = unpack::u32_to_u8(0xff00ff00);
// Returns [0xff, 0x00, 0xff, 0x00]

It's important to note, when packing, the least significant byte in the input slice (at index 0) becomes the most significant byte in the output value.

When unpacking, the most significant byte in the input value becomes the least significant byte in the output array (at index 0).

Commit count: 1

cargo fmt