Crates.io | intpack |
lib.rs | intpack |
version | 0.1.0 |
source | src |
created_at | 2021-09-28 00:30:40.862257 |
updated_at | 2021-09-28 00:30:40.862257 |
description | 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. |
homepage | |
repository | https://github.com/Will-Banksy/intpack |
max_upload_size | |
id | 457277 |
size | 7,259 |
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) !!
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).