More number conversion code

100% coverage
This commit is contained in:
2025-06-02 10:25:59 -04:00
parent 60232b958f
commit 12d738389b
5 changed files with 84 additions and 30 deletions
+13 -10
View File
@@ -81,17 +81,20 @@ impl NumberSystemConversion {
low | high << 8
}
/// combine_u8_to_u16
///
/// Combines a pair of u8 values into a single u16 with high
/// and low bytes specified
///
/// ex: (0xff, 0x00) -> 0x00ff
/// (0x00, 0xff) -> 0xff00
/// (0xbe, 0xef) -> 0xefbe
/// (0xef, 0xbe) -> 0xbeef
pub fn combine_u8_to_u16(low: u8, high: u8) -> u16 {
(high as u16) << 8 | low as u16
}
pub fn join_bytes_u16_from_u8(high: u8, low: u8) -> u16 {
low as u16 | ((high as u16) << 8)
}
pub fn split_bytes_u32(from: u32) -> (u16, u16) {
let mut bytes = vec![];
bytes[0] = (from & 0xffff) as u16;
bytes[1] = ((from & 0xffff0000) >> 16) as u16;
(bytes[0], bytes[1])
}
pub fn split_bytes_u32_4(from: u32) -> (u8, u8, u8, u8) {
(0, 0, 0, 0)
}
}