NCD-encoder, DCD decoder with xxM2 ?

elektriker

New Member
Hello everybody!

Is there a way to program 'NCD' and 'DCD' for Picaxe xxM2 ?

How can I do that ?

Thank you very much
 

Jeremy Harris

Senior Member
Only the X1 and X2 parts support NCD/DCD, according to the command reference.

(NCD is the 2n power encoder, DCD is the 2n power decoder)
 

hippy

Technical Support
Staff member
DCD delivers a 2n result, "DCD 0" gives a 1 result, "DCD 1" gives a 2 result, "DCD 2" gives a 4 result, "DCD 15" gives a 32768 result.

"DCD n" can be done as ...

LOOKUP n, ( 1, 2, 4, 8, 16, ... , 16384, 32768 ), var

NCD does the opposite - almost.

"NCD w0" can be done as ...

LOOKDOWN 1, ( bit15, bit14, ... , bit1, bit0, 1 ), var : var = 16 - var
 

AllyCat

Senior Member
Hi,

I knew it would be possible, but I'm lazy, so having found some suitable search terms, I found this thread, see posts #25 and #28. Thanks hippy and WA55. ;)

EDIT: Ah, hippy is faster than a forum serach. ;)

Cheers, Alan.
 

BESQUEUT

Senior Member
Ah, hippy is faster than a forum search. ;)

Cheers, Alan.
And always the simplest code...
Code:
[color=Navy]#macro [/color][color=Black]_NCD[/color][color=Blue]([/color][color=Black]A[/color][color=Blue])
  [/color][color=Purple]b1[/color][color=DarkCyan]=[/color][color=Navy]0
  [/color][color=Blue]if [/color][color=Purple]b0[/color][color=DarkCyan]>[/color][color=Navy]0 [/color][color=Blue]then
      inc [/color][color=Purple]b1
      [/color][color=Blue]do while [/color][color=Purple]bit0 [/color][color=DarkCyan]= [/color][color=Navy]0
         [/color][color=Blue]inc [/color][color=Purple]b1
         b0[/color][color=DarkCyan]=[/color][color=Purple]b0[/color][color=DarkCyan]/[/color][color=Navy]2
      [/color][color=Blue]loop 
  endif[/color]
[color=Navy]#endmacro[/color]


[color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy]%100[/color]
[color=Green]'b1=ncd b0[/color]
[color=Black]_NCD[/color][color=Blue]([/color][color=Purple]b0[/color][color=Blue])


sertxd([/color][color=Red]"NCD="[/color][color=Black],#[/color][color=Purple]b1[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue])[/color]
 

premelec

Senior Member
I learn something every day... including that UNARY commands aren't listed in the BASIC command set index [ref above this forum's posts] and still don't know what - if anything - NCD and DCD stand for; though I now know their function... so much to learn...
 

premelec

Senior Member
I LET go many years ago - I thought perhaps they'd be under UNARY... finally I used search in Manual 2 PDF file... ;-0 looks like it should be {LET} ;-)
 
Last edited:
Top