Bits - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Bits : Bits/FirstNonzeroBit

Bits

  

FirstNonzeroBit

  

locate first nonzero bit from a location in a specified direction

 

Calling Sequence

Parameters

Description

Examples

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

withBits:

FirstNonzeroBit255=ilog2255

7=7

(1)

FirstNonzeroBit256=ilog2256

8=8

(2)

FirstNonzeroBit0ilog20

1∞

(3)

FirstNonzeroBit1+2+4+256,higher

0

(4)

FirstNonzeroBit1+2+4+256,higher,1

1

(5)

FirstNonzeroBit1+2+4+256,higher,2

2

(6)

FirstNonzeroBit1+2+4+256,higher,3

8

(7)

FirstNonzeroBit1+2+4+256,higher,9

∞

(8)

FirstNonzeroBit1,lower

∞

(9)

FirstNonzeroBit1,lower,5

5

(10)

See Also

Bits

ilog2

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam