In SX Microcontrollers, SX/B Compiler and SX-Key Tool, tsaavik wrote: Hey all, I've been playing around with the Stampworks examples with my SX28. I've been trying to keep with the spirit of each project and not cheat my way past the hard stuff :D Today while working on example 5 i ran into the "DCD" command used by the basic stamps, and not available under sx/b. [quote="Regarding DCD the basic Stamp manual"] The Decoder operator (DCD) is a 2[sup]n[/sup] - power decoder of a four-bit value. DCD accepts a value from 0 to 15, and returns a 16-bit number with the bit, described by value, set to 1. for example: result VAR Word result = DCD 12 ' Set bit 12 DEBUG BIN16 ? result ' Display result (%0001000000000000) [/quote] I wrote this function, and the program works as described in Stampworks, but i wonder if i really got it "right" or just cheated. [code] ' -----[ Variables ]------------------------------------------------------- dcdIN VAR Byte dcdOut VAR Word ' -----[Subs ]------------------------------------------------------------ DCD Func 1,2 [/code] [code] DCD: dcdIn = __PARAM1 dcdOut = $0001 Do While dcdIn > 1 dcdOut = dcdOut << 1 dec dcdIn Loop RETURN dcdOut [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=181771 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)