[ Arithmetic | Reference Manual | Alphabetic Index ]
msb(+Number, -Result)
-Result is msb(+Number)
Result is the index of the most significant nonzero bit
- Number
- Positive Integer
- Result
- Output: integer.
Description
Returns the index of the most 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 msb(1). % gives Result = 0.
Result is msb(4). % gives Result = 2.
Result is msb(40). % gives Result = 5. (40 is binary 101000)
See Also
is / 2, getbit / 3, clrbit / 3, setbit / 3, lsb / 2, popcount / 2