34 lines
519 B
C++
34 lines
519 B
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
namespace mp::utils
|
|
{
|
|
|
|
template <class T>
|
|
inline constexpr T GetNBytesMask(size_t bytes)
|
|
{
|
|
T res = 0;
|
|
|
|
for (size_t i = 0; i < bytes; ++i)
|
|
{
|
|
res <<= 8;
|
|
res |= 0xFF;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
inline char HexDigit(uint8_t bits)
|
|
{
|
|
return bits > 9 ? 'a' + (bits - 10) : '0' + bits;
|
|
}
|
|
|
|
inline constexpr size_t AlignUp(size_t value, size_t alignment)
|
|
{
|
|
return (value + alignment - 1) / alignment * alignment;
|
|
}
|
|
|
|
} // namespace mp::utils
|