< /p>
>
исходные данные: b1 b2 b3 b4
ожидаемые данные: b4 b3 b2 b1
Возвращенные данные: b3 b4 b1 b2
< /p>
исходный код: < /p>
Код: Выделить всё
#include
#include
#include
#include
template
inline T convert_endianness(T input) //Will only work with positive numbers
{
if constexpr (std::is_same_v) // if (std::is_same::value)
{
return __bswap_16(input);
}
else if constexpr (std::is_same_v) // if (std::is_same::value)
{
return __bswap_32(input);
}
else if constexpr (std::is_same_v) // if (std::is_same::value)
{
return __bswap_64(input);
}
else
{
static_assert("Invalid Data Type in convert_to_big_endian. The following data types are only supported std::uint16_t, std::uint32_t, std::uint64_t");
}
}
int main(void)
{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79413977/using-bswap-16-bswap-32-bswap-64-to-change-endiannes-gives-improper-output[/url]
Мобильная версия