NCD vs. DCD - Commentary


Results 1 to 3 of 3

Threaded View

  1. #2
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default Look in the manual

    NDC has a range of 1-16 but gives a result of 0 if no bit is set. So you can say it has 17 possible results (0-16)
    NDC %00000000 equals 0
    NDC %00000001 equals 1
    NDC %00000010 equals 2
    NDC %00000100 equals 3
    to
    NDC %1000000000000000 equals 16

    NDC %1111111111111111 also equals 16 because NDC is only checking the highest bit set.

    DCD is a bit different it has (0-15) as range

    DCD 0 would give %00000001
    DCD 1 would give %00000010
    DCD 2 would give %00000100

    So you see in DCD you use a BIT reference number and PBP mostly counts bits from 0-7 if it is a byte and 0-15 if it is a word.

    So the easy answer to your question is that NDC and DCD are not symetrical because they are not the reverse function of each other.

    BUT....
    IF you want you can do like this and get a better result.
    Just remember you will "loose" the highest bit but if you use this to set a port it is no problem as long as you do the shifting in a Word size variable.

    Temp Var Word
    A var Byte

    Temp= DCD 0 'Temp=%0000000000000001
    Temp=Temp>>1 'Temp=%0000000000000000
    A=NDC Temp 'A equals 0

    Temp=DCD 15 'Temp=%1000000000000000
    Temp=Temp>>1 ''Temp=%0100000000000000
    A=NDC Temp 'A equals 15
    Last edited by sinoteq; - 3rd November 2007 at 07:45.

Similar Threads

  1. DCD command - need some advice
    By malc-c in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th December 2006, 03:43
  2. Music notes and DIG, DCD, and NCD ?
    By websmith in forum General
    Replies: 2
    Last Post: - 9th November 2006, 14:28
  3. Use of DIG, DCD, NCD
    By websmith in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th November 2006, 06:14
  4. Pic Basic Pro Syntax
    By Finn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th January 2004, 18:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts