Ncd
Positron16 · Revision 1.1.3.5 · PDF page 121
Syntax
Assignment Variable = Ncd (pVariable)
Overview
Priority encoder of a 16-bit or 32-bit value. Ncd takes a value, finds the highest bit containing a 1 and returns the bit position plus one (1 through 32). 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.
Parameter
pVariable can be a floating point constant, variable or expression. Assignment Variable can be any valid variable type.
Example
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyWord as Word
Dim MyResult as Word
RPOR7 = 3 ' Make PPS Pin RP14 U1TX
MyWord = %00001101 ' Highest bit set is bit-3.
MyResult = Ncd MyWord
HrsoutLn Dec MyResult ' Display the Ncd of MyWord1(4).
Ncd does not support Float or Double type variables.
