Positron Compiler Documentation

Ncd

Positron8 · Revision 4.0.6.5 · PDF page 109

Assignment Variable = Ncd(pVariable)

Priority encoder of a 16-bit value. Ncd takes a 16-bit value, finds the highest bit containing a 1 and returns the bit position plus one (1 through 16). If no bit is set, the input value is 0. Ncd returns 0. Ncd is a fast way to get an answer to the question "what is the largest power of two that this value is greater than or equal to?" The answer that Ncd returns will be that power, plus one.

pVariable can be a constant, variable or expression. Assignment Variable can be any valid variable type.

Device = 18F26K40             ' Select the device to compile for
Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600   ' Set the Baud rate for HRsoutLn

Dim MyWord as Word

MyWord = 0b00001101           ' Highest bit set is bit-3.
HRsoutLn Dec Ncd MyWord        ' Display the Ncd of MyWord (4).

Ncd does not, yet, support Long, Dword, or Float type variables.

View original PDF page 109Open page in PDFOriginal PDF page 109