Output decimal number as Binary on a relay card.
travis
Posts: 180
Just leaving this here. Got most of it from another thread, so thanks.
I don't like the variable/param/function names, but naming stuff is like the hardest part of programming.
DEFINE_CALL'DECIMAL_TO_RELAY_CARD'(DEV rly, INTEGER iDecimalNumber){ //convert a decimal number into it's binary representation on a relay card LOCAL_VAR INTEGER itmp64 FOR(itmp64 = 1; itmp64 <=8; itmp64++){ [rly,itmp64] = iDecimalNumber & REL_MASKS[itmp64] } }
DEFINE_CONSTANT INTEGER REL_MASKS[8] = {1,2,4,8,16,32,64,128}
I don't like the variable/param/function names, but naming stuff is like the hardest part of programming.
0
Comments
Easily modified to make a binary clock in your card cage to impress even the most 1/0 savvy client
This technique gets a lot of use in the Windows API for passing window flags into API functions, allowing users to pass in any combination of the pre-defined flags.
Oh nice. Maybe I can use this elsewhere...
Personally I prefer your initial version using the lookup table, its simple and neat. Also, as you only have 8 relays to play with (assuming you're talking about the internal ones) this limits you to a single byte rather than an integer.
If you're just wanting to represent values and don't care about the convenience of the flag pattern shown by Bigsquatch you can do away with the table altogether:
Alternatively, if you needed to represent an integer you could do so using both the relays and io's:
</procrastination>
I have a pair of these new-fangled EXB-REL8's at the moment to procrastinate with. Actually, this is for a project. I don't know what you all's excuses are.