Bits[FirstNonzeroBit] - locate first nonzero bit from a location in a specified direction
|
Calling Sequence
|
|
FirstNonzeroBit(number)
FirstNonzeroBit(number,dir)
FirstNonzeroBit(number,dir,posn)
|
|
Parameters
|
|
number
|
-
|
an integer
|
dir
|
-
|
either higher or lower, indicating the direction of the search
|
posn
|
-
|
bit offset to start search at
|
|
|
|
|
Description
|
|
•
|
The FirstNonzeroBit command locates the first nonzero bit in a number in a specified direction from a specified location.
|
By default, the command searches in the lower direction starting at the most significant bit in the number. In this way, calling it with no additional arguments gives an identical result as the ilog2 command.
Note that for negative numbers, the most significant bit does not exist, so infinity is returned.
•
|
If dir is specified as lower, then the number will be searched in the direction of the most significant bit to the least significant bit.
|
If posn is not specified, it defaults to the most significant bit in the number.
If there are no bits lower than posn, -1 is returned.
•
|
If dir is specified as higher, then the number will be searched in the direction of the least significant bit to the most significant bit.
|
If posn is not specified, it defaults to 0.
If there are no bits higher than posn, infinity is returned.
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
| (9) |
>
|
|
| (10) |
|
|
Download Help Document
Was this information helpful?