Bit Limits#

Defined in namespace hal

#include <libhal-util/bit_limits.hpp>

group BitLimits

Functions

template<size_t BitWidth, std::integral T>
consteval T generate_field_of_ones()#

Generate a mask of 1s at compile time.

Template Parameters:
  • BitWidth – - number of 1s in the mask

  • T – - the type

Returns:

consteval uint32_t - mask with 1s at the LSB

static inline constexpr int_t max()#

Get the maximum value available for an integer of BitWidth size and that can be stored within int_t.

The final value of the function depends also on the sign of the int type.

Returns:

constexpr int_t maximum value

static inline constexpr int_t min()#

Get the minimum value available for an integer of BitWidth size and that can be stored within int_t.

The final value of the function depends also on the sign of the int type. Unsigned ints simply return zero.

Returns:

constexpr int_t minimum value

template<size_t BitWidth, std::integral int_t>
struct bit_limits#
#include <bit_limits.hpp>

Similar to std::numeric_limits<T> except that this object can give properties of integral types of arbitrary bit widths.

Template Parameters:
  • BitWidth – - bit width of the value

  • int_t – - the containing type. Will generate a compile error if the containing type’s bit width is smaller than the BitWidth value.

Public Static Functions

static inline constexpr int_t max()#

Get the maximum value available for an integer of BitWidth size and that can be stored within int_t.

The final value of the function depends also on the sign of the int type.

Returns:

constexpr int_t maximum value

static inline constexpr int_t min()#

Get the minimum value available for an integer of BitWidth size and that can be stored within int_t.

The final value of the function depends also on the sign of the int type. Unsigned ints simply return zero.

Returns:

constexpr int_t minimum value