If you haven't been to Daniel Roth's site on behavior based robots, you ought to.
For instance. Joe's sensor returns a 1 or a 0 for detection or nondetection. He wants to change it to a direction for a wheel; 1, -1. What's a really simple way to do it? 2w - 1. So 2* w will give a 2 or a
- Then -1 will give a 1 or a -1. Slick.
Now going beyond the book for a moment, a multiply by two is a ASL (arithmetic shift left) in most machine codes, and a -1 is usually a single instruction as well, like SUB #1, or ADD #-1, or what have you. So this technique could compile to an extremely compact two instruction sequence. He doesn't go into that detail, just mentions the conversion.
Now in my systems, I generally get a 0 for false and FFFF or -1 for true. I'd do a 2* and a 1+ to get the same effect (but sense would be inverted).
So again, I think Joe's got a winner here. I'm glad to have the book.