chsvlib
chsv helper source code

◆ bsf()

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

Returns an index of the rightmost (least 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 least significant nonzero bit.
Returns
An index of the least significant nonzero bit within the integer val. If val is zero, i.e. all bits of it are reset, the function returns a size of an object of the type T in bits.

Assuming that val = x, \(x \ne 0\) and \(x = x'\cdot 2^f\), where \(x, x'\in\mathbb{Z}\), and \(x'\) is odd, the function returns the value \(f = \log_2\frac{x}{x'}\).

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

See also
bsr.