chsvlib
chsv helper source code

◆ bsr()

constexpr std::uint8_t Chusov::Memory::bsr ( val)
constexprnoexcept

Returns an index of the leftmost (most significant) nonzero bit of an integer.

Template Parameters
TA deduced integral type of the parameter.
Parameters
valThe integral value in which the function scans the most significant nonzero bit.
Returns
An index of the most significant nonzero bit within the integer val or, if val is zero, i.e. all bits of it are reset, a size of an object of the type T in bits.

If x = val is not zero, the function effectively returns \(\left\lceil\log_2 x\right\rceil\).

The function requires that a size of a byte is exactly eight bits.

See also
bsf.