Positron Compiler Documentation

Ncd

Source: Positron8 Compiler User Manual, PDF page 109

Syntax

Assignment Variable = Ncd(pVariable)

Overview

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.

Parameter

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

Example

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.