NeKernel dev
Loading...
Searching...
No Matches
bit.h File Reference
#include <bit>

Go to the source code of this file.

Namespaces

namespace  utl

Functions

template<class T>
constexpr auto utl::bit_size ()
 Size of object in terms of bits.
template<class T>
constexpr T utl::bit_full ()
 Integer with all bits set to 1.
template<class T>
constexpr T utl::bit_wrap ()
 Wrap around mask for power of two number of bits within given integer type. For example: [ bit_wrap<uint8_t> = 8 - 1 = 0b111 ] [ bit_wrap<uint16_t> = 16 - 1 = 0b1111 ] [ bit_wrap<uint32_t> = 32 - 1 = 0b11111 ].
template<class T>
constexpr auto utl::bit_shft ()
 Number of bits to fit bit_wrap<T> result, in other words bit width of (sizeof(T) * 8 - 1). For example: [ bit_shft<uint8_t> = bit_width(0b111) = 3 ] [ bit_shft<uint16_t> = bit_width(0b1111) = 4 ] [ bit_shft<uint32_t> = bit_width(0b11111) = 5 ].
template<class T>
constexpr auto utl::bit_ceil (auto x)
 Round up division by number of bits within given integer type, which sizeof(T) * 8 is power of two.
constexpr unsigned utl::cntlz (auto x)
 Count leading zeros.
constexpr unsigned utl::cnttz (auto x)
 Count trailing zeros.
template<class T>
constexpr size_t utl::words_in_bits (size_t n)
 Get number of words (integers) required to store N bits.
constexpr size_t utl::bytes_in_bits (size_t n)
 Get number of bytes required to store N bits.
template<class T = unsigned>
constexpr T utl::bit (int n)
 Make integer with bit at given position.
template<class T>
constexpr bool utl::get_bit (T x, int n)
 Get n-th bit of an integer.
template<class T>
constexpr void utl::set_bit (T &x, int n)
 Set n-th bit of an integer.
template<class T>
constexpr void utl::clr_bit (T &x, int n)
 Clear n-th bit of an integer.
template<class T>
constexpr bool utl::get_arr_bit (const T *p, unsigned n)
 Get n-th bit in array of words (starting from LSB).
template<class T>
constexpr void utl::set_arr_bit (T *p, unsigned n)
 Set n-th bit in array of words (starting from LSB).
template<class T>
constexpr void utl::clr_arr_bit (T *p, unsigned n)
 Clear n-th bit in array of words (starting from LSB).
template<class T, size_t L>
constexpr void utl::shift_left (T(&x)[L])
 Shift bits left in array of integer elements from least significant bit and considering 0-th byte as the right most. uint16_t example: 0b10000000'11100001 ==> 0b00000001'11000010.