Module malachite_base::num::conversion::half
source · Expand description
JoinHalves
and SplitInHalf
, traits for joining
the bits of two numbers or for splitting a number in half.
§join_halves
use malachite_base::num::conversion::traits::JoinHalves;
assert_eq!(u16::join_halves(1, 2), 258);
assert_eq!(u32::join_halves(0xabcd, 0x1234), 0xabcd1234);
§split_in_half
use malachite_base::num::conversion::traits::SplitInHalf;
assert_eq!(258u16.split_in_half(), (1, 2));
assert_eq!(0xabcd1234u32.split_in_half(), (0xabcd, 0x1234));
§lower_half
use malachite_base::num::conversion::traits::SplitInHalf;
assert_eq!(258u16.lower_half(), 2);
assert_eq!(0xabcd1234u32.lower_half(), 0x1234);
§upper_half
use malachite_base::num::conversion::traits::SplitInHalf;
assert_eq!(258u16.upper_half(), 1);
assert_eq!(0xabcd1234u32.upper_half(), 0xabcd);