Shop OBEX P1 Docs P2 Docs Learn Events
NCD — Parallax Forums

NCD

ArchiverArchiver Posts: 46,084
edited 2003-06-11 17:54 in General Discussion
Does anyone know how NCD command works internal to BS2?
I've been using it, but I wish to gain some insight on its internal
operations.

Much thanks in advance.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-06-11 17:54
    NCD X finds the position of the most significant bit in X, from 1 to
    16. If no bit is set, then NCD X = 0.

    examples
    NCD 9 = 4 ' 9=%1001
    NCD 32768 = 16 ' 32768=%100000000000
    NCD 1 = 1
    NCD 0 = 0




    Pseudocode implementation:
    X=number to test
    Y=16 ; bit counter
    NCD_test
    shift X left through carry
    if carry=1 or Y=0 then
    exit_NCDtest
    else
    decrement Y
    goto NCD_test
    endif
    ; exit with Y=NCD X

    On my web pages I have a writeup on how to use NCD as the start of a
    logarithm function--It is the characteristic of log base2 X.

    -- Tracy



    >Does anyone know how NCD command works internal to BS2?
    >I've been using it, but I wish to gain some insight on its internal
    >operations.
    >
    >Much thanks in advance.
Sign In or Register to comment.