::std::num::

Function concat

pub extern fn concat<N, M, K>(x: N, y: M) -> K
Expand

Creates an integer by concatenating the bits of two existing ones.

The result is an integer whose higher bits correspond to the first input integer, and its lower bits correspond to the second one. In other words, given two numbers 0x123 and 0x456, the result is 0x123456.

Note that when operating with signed integers, the result has the same sign as the first argument provided, as it is its most significant bit which becomes the sign bit of the concatenated whole.

Examples

assert std::num::concat(0xABADu16, 0x1DEAu16) == 0xABAD_1DEAu32;
assert std::num::concat(0x1234i16, 0x5678i16) == 0x1234_5678i32;
assert std::num::concat(0i16, -1i16) == 65_535i32;
assert std::num::concat(0u0, 0u0) == 0u0;