-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Little endian support #3
Comments
Or maybe a default parameter #ifdef _WIN32
#define __LITTLE_ENDIAN 1234
#define BYTE_ORDER __LITTLE_ENDIAN
#endif
enum class ByteOrder : uint32_t {
little_endian = __LITTLE_ENDIAN,
big_endian = __BIG_ENDIAN,
};
template<class T>
T to_variable(const uint8_t* block, ByteOrder byte_order = static_cast<ByteOrder>(BYTE_ORDER)) |
Hi, thanks for support, |
Yes, I will create a MR For the project I am working on I ended up with this - https://godbolt.org/z/Tz7Wvg uint16_t load_uint16_from_le(const uint8_t *raw_data)
{
return ((uint16_t)(raw_data[1]) << 8) | (uint16_t)raw_data[0];
}
uint16_t load_uint16_from_be(const uint8_t *raw_data)
{
return ((uint16_t) (raw_data[0]) << 8) | (uint16_t) raw_data[1];
}
uint32_t load_uint32_from_le(const uint8_t *raw_data)
{
return (uint32_t)(raw_data[3]) << 24 | (uint32_t)raw_data[2] << 16 | (uint32_t)raw_data[1] << 8 | (uint32_t)raw_data[0];
}
uint32_t load_uint32_from_be(const uint8_t *raw_data)
{
return ((uint32_t)(raw_data[0]) << 24) | (uint32_t)raw_data[1] << 16 | (uint32_t)raw_data[2] << 8 | (uint32_t)raw_data[3];
} I will refactor this code to fit your library. So
|
Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi :)
Thank you for such a simple yet working library.
I noticed that this library only supports big endianness. I want to use it on x86 system and to use this library I would have to reverse bytes first.
Can you add functions like
and
The text was updated successfully, but these errors were encountered: