
getbit(+Number, +Index, -Result)
-Result is getbit(+Number, +Index)

   Result is the Index'th bit of Number.



Arguments
   Number              Integer.
   Index               Non-negative integer.
   Result              Output: integer.

Type
   Arithmetic

Description
   Returns the Index'th bit of Number, assuming binary two's complement
   representation.  The least significant bit has index zero.
   The result is either 0 or 1.

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




Modes and Determinism
   getbit(+, +, -) is det

Exceptions
     4 --- Number or Index is not instantiated (non-coroutining mode    only).
     5 --- Number or Index is a number but not an integer.
    24 --- Number or Index is not of a numeric type.

Examples
   
    % 10 is binary 1010
    Result is getbit(10, 3).		% gives Result = 1.
    Result is getbit(10, 2).		% gives Result = 0.
    Result is getbit(10, 99).		% gives Result = 0.

    % Test for a 1-bit:
    getbit(10, 3, 1)                    % succeeds
    getbit(10, 2, 1)                    % fails

    % Test for a 0-bit:
    getbit(10, 3, 0)                    % fails
    getbit(10, 2, 0)                    % succeeds


See Also
   is / 2, clrbit / 3, setbit / 3, lsb / 2, msb / 2, popcount / 2
