Skip to main content

array_to_unsigned

Function array_to_unsigned 

Source
pub fn array_to_unsigned<T>(parts: &[u8]) -> Result<T>
where u128: From<T>, T: FromStr + TryFrom<u128>, <T as FromStr>::Err: Debug + Error, <T as TryFrom<u128>>::Error: Error + Send + Sync + 'static,
Expand description

Join a Vec of u8s into an unsigned integer

Say you have the array [0b00000110, 0b10110101] and want to use it as a u32. This function sets it together to a integer type of your choosing: 1717 (binary: 00000000 00000000 00000110 10110101).

If the array is not long enough, the number will be padded with null bytes.

ยงExamples


let x: [u8; 2] = [0b00000110, 0b10110101];

assert_eq!(array_to_unsigned::<u32>(&x).unwrap(), 1717);