The BIT_FFS function returns the index of the first bit set (non-zero) in its integer argument.

Example


Binary integer arithmetic has the property that any integer value with a single bit set is a power of 2. For example, the value 1024 is equivalent to 210. The following statement uses BIT_FFS to determine the power to which 2 must be raised to yield 1024:

p = BIT_FFS(1024) - 1
PRINT, FORMAT='(%"2^%d = %d")', p, 2^p

IDL prints:

2^10 = 1024

Syntax


Result = BIT_FFS( Value )

Return Value


BIT_FFS returns the index of the first bit set in Value. Bits are numbered starting at one (the least significant bit). Zero (0) is returned if Value has no bits set. If Value is an array, the result is an array with the same structure, where each element contains the index of the first bit set in the corresponding element of Value.

Arguments


Value

A scalar or array of any integer type.

Keywords


Thread Pool Keywords

This routine is written to make use of IDL’s thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the !CPU system variable control whether IDL uses the thread pool for a given computation. In addition, you can use the thread pool keywords TPOOL_MAX_ELTS, TPOOL_MIN_ELTS, and TPOOL_NOTHREAD to override the defaults established by !CPU for a single invocation of this routine. See Thread Pool Keywords for details.

Version History


6.2

Introduced