[ Arithmetic | Reference Manual | Alphabetic Index ]

lsb(+Number, -Result)

-Result is lsb(+Number)

Result is the index of the least significant nonzero bit
Number
Positive Integer
Result
Output: integer.

Description

Returns the index of the least significant nonzero bit in Number's binary representation. The least significant bit has index zero. Only defined for Number greater than zero.

This predicate can be used as a function in arithmetic expressions. In coroutining mode, if Number is uninstantiated, the call is delayed until it is instantiated.

Modes and Determinism

Exceptions

(4) instantiation fault
Number or Index is not instantiated (non-coroutining mode only).
(5) type error
Number or Index is a number but not an integer
(6) out of range
Number is less than 1
(24) number expected
Number or Index is not of a numeric type

Examples

    Result is lsb(1).           % gives Result = 0.
    Result is lsb(4).           % gives Result = 2.
    Result is lsb(40).          % gives Result = 3. (40 is binary 101000)

See Also

is / 2, getbit / 3, clrbit / 3, setbit / 3, msb / 2, popcount / 2